简体   繁体   English

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

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

folder structure:文件夹结构:

在此处输入图片说明

I'm unable to reach test.html which is under resources/static folder:我无法访问资源/静态文件夹下的 test.html:

src-> main-> java-> resources -> static -> test.html

http://localhost:8080/test.html (not working) http://localhost:8080/test.html (不工作)

but able to reach index.html under:但能够在以下情况下访问 index.html:

src-> main-> java-> webapp-> index.html

http://localhost:8080/index.html (working) http://localhost:8080/index.html (工作)

from Spring Boot docs, it seems that I supposed to put all of my static content under /src/main/resources/static从 Spring Boot 文档来看,我似乎应该将所有静态内容放在 /src/main/resources/static 下

extra info: <packaging>war</packaging>额外信息: <packaging>war</packaging>

WEB-INF inside the war file: war 文件中的 WEB-INF:

在此处输入图片说明

any idea why I'm not able to reach test.html?知道为什么我无法访问 test.html 吗?

You must add file extension: "index.html".您必须添加文件扩展名:“index.html”。 Another option (if you want to make it work without extension) is adding thymeleaf dependency to pom.xml.另一种选择(如果你想让它在没有扩展的情况下工作)是将 thymeleaf 依赖项添加到 pom.xml。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

You need to actually place the content in a folder named static.您需要将内容实际放置在名为 static 的文件夹中。

The hierarchy would be src/main/resources/static/index.html层次结构将是 src/main/resources/static/index.html

Now you want to keep your resources into the resource folder which IS NOT in the现在您想将您的资源保存在资源文件夹中,该文件夹不在

src-> main-> java

By default Spring-boot is searching for the .html files uder that directory :默认情况下,Spring-boot 正在搜索该目录下的.html文件:

src-> main-> resources-> templates

As I can see you are saying that you put yours into the :正如我所看到的,你是说你把你的放入:

src-> main-> JAVA-> resources

Which is wrong.这是错误的。

Simple :简单的 :

在此处输入图片说明

Keep your Controllers, Services, Repositories and so on into the java folder and keep your resources into the resources one.将您的控制器、服务、存储库等保存在java文件夹中,并将您的资源保存在resources之一中。 Where you can have a static folder for css, fonts, img, js and a templates folder where you should keep your htmls .您可以在其中拥有一个用于css、字体、img、jsstatic文件夹和一个templates文件夹,您应该在其中保存htmls

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

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