Spring Boot - html文件的正确位置

时间:2016-03-19 17:36:20

标签: java spring-boot

我是Spring Boot的新手,我正在尝试为我的项目添加一个简单的html页面 目前,我的项目结构如下:

enter image description here

阅读以下内容: https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot

http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-static-content

和StackOverflow中的其他答案,我希望在访问http://localhost:8080/

时看到index.html的内容

我能错过什么?

2 个答案:

答案 0 :(得分:0)

首先介绍在Spring Boot中提供文件的正确方法 cannot find html pages with spring boot

添加所需的目录后,我尝试了/services/login.html,其中“services”是我的Dispatcher servlet的映射。 所以这里发生的事情是,Spring Boot只会回复发送到/ services / *的请求,即使这些请求指向的不是控制器。 我想这在Spring Boot世界中是有意义的,但是当我在Spring MVC项目(没有Spring Boot)中尝试相同时,我能够访问我刚刚添加到WEB-INF目录中的简单html文件

答案 1 :(得分:0)

由于SpringBoot项目中没有webapp,我们可以将html文件放在

src/main/resources/resources/index.html
src/main/resources/static/index.html 
src/main/resources/public/index.html 

请记住,上面是从最高到最低的优先级。

要检查文件,请在eclipse中运行主类,然后转到http://localhost:8080/index.html