繁体   English   中英

Spring boot 在 resoures 文件夹下找不到 index.html

[英]Spring boot cannot find index.html under resoures folder

文件夹结构:

在此处输入图片说明

我无法访问资源/静态文件夹下的 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>

您需要将内容实际放置在名为 static 的文件夹中。

层次结构将是 src/main/resources/static/index.html

现在您想将您的资源保存在资源文件夹中,该文件夹不在

src-> main-> java

默认情况下,Spring-boot 正在搜索该目录下的.html文件:

src-> main-> resources-> templates

正如我所看到的,你是说你把你的放入:

src-> main-> JAVA-> resources

这是错误的。

简单的 :

在此处输入图片说明

将您的控制器、服务、存储库等保存在java文件夹中,并将您的资源保存在resources之一中。 您可以在其中拥有一个用于css、字体、img、jsstatic文件夹和一个templates文件夹,您应该在其中保存htmls

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM