如何在spring-boot中提供静态html内容页面 [英] How to serve static html content page in spring-boot

查看:999
本文介绍了如何在spring-boot中提供静态html内容页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 spring-boot 启动嵌入式tomcat,并希望提供静态 index.html 页面作为正在运行的应用程序的一部分。

I'm starting an embedded tomcat via spring-boot and want to serve a static index.html page as part of a running application.

但以下不起作用:

@SpringBootApplication
public class HMyApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}


@RestController 
public class HomeContoller {
    @RequestMapping("/")
    public String index() {
        return "index";
    }
}

src/main/resources/static/index.html

结果:当我打电话给 localhost:8080 时,我只看到index这个词,但不是我的html页面。为什么?

Result: when I call localhost:8080, I just see the word "index", but not my html page. Why?

推荐答案

我的错:我有一个额外的课程 @EnableWebMvc 注释。这在某种程度上搞砸了spring-boot自动配置。我删除了它,现在它可以返回 index.html

My fault: I had an additional class with @EnableWebMvc annotation. This somehow messed up the spring-boot autoconfiguration. I removed it and now it works returning index.html.

这篇关于如何在spring-boot中提供静态html内容页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆