文件夹结构:
我无法访问 resources/static 文件夹下的 test.html:
src-> main-> java-> resources -> static -> test.html
http://localhost:8080/test.html (不工作)
但能够在以下位置访问 index.html:
src-> main-> java-> webapp-> index.html
http://localhost:8080/index.html (工作)
从 Spring Boot 文档来看,我似乎应该将所有静态内容放在/src/main/resources/static 下
额外信息:<packaging>war</packaging>
war 文件中的 WEB-INF:
知道为什么我无法访问 test.html 吗?
最佳答案
您必须添加文件扩展名:“index.html”。 另一种选择(如果你想让它在没有扩展的情况下工作)是 将 thymeleaf 依赖项添加到 pom.xml。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
关于java - spring boot 找不到资源文件夹下的 index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41171861/