【发布时间】:2020-08-07 03:57:10
【问题描述】:
我是 Springboot 的新手,我正在尝试在其根 (localhost:8080) 路径上显示 html 页面。为此,我用谷歌搜索并浏览了 -
- Spring Boot not serving static content
- https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot
- Spring Boot app not serving static content
- Springboot does not serve static content
几乎尝试了所有方法,但没有一个对我有用。
确切的问题
没有任何资源/(静态/或公共/或元信息/资源)中的 index.html 文件可以正常工作并显示一些弹簧数据的列表。如果我创建一个 index.html 文件,那么它会给出一个错误 404 not found without @EnableWebMvc annotation,如果使用 @EnableWebMvc 那么它会显示 Spring data rest apis 的列表。
除了 index.html 文件,它在根路径中显示 Spring 数据 api 的列表,并且 index.html 以外的 url(localhost:8080/test.html) 也有同样的问题。
使用此配置实现public class StaticResourceConfiguration implements WebMvcConfigurer 不会影响此问题。
【问题讨论】:
-
@Shubh 对我不起作用,谢谢你的链接.. 我错过了这一点
标签: java spring-boot static-content