java - spring boot 找不到资源文件夹下的 index.html

标签 java maven web-applications spring-boot static-content

文件夹结构:

enter image description here

我无法访问 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:

enter image description here

知道为什么我无法访问 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/

相关文章:

java - 按时间间隔 hibernate 分组

eclipse - Maven 插件是否会更改 Eclipse 中“运行”按钮(绿色三角形)的操作?

java - Gridview 类似于 Java 中 hibernate 对象的显示?

javascript - 保持滚动位置的单页 webapp 屏幕转换

java - 将对象的新实例注入(inject)每个请求处理程序

java - 构造一个 jar ?

java - 我应该导入哪个 .jar 以便 "import com.android.widget"解析为类型?

java - Maven - 在当前项目和插件组中找不到前缀 'tomcat7' 的插件

java - 在最大尝试次数后,Testng RetryListener 未使测试用例失败

java - 使用 Stripes 将 JSP 文件移动到 WEB-INF 目录时出错