2016-12-15 51 views
1

文件夹结构:春天开机找不到resoures文件夹下的index.html

enter image description here

我无法达到的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(工作)

从春天启动文档,看来我应该把我的下/ src目录/主/资源静态内容/静态

额外的信息:<packaging>war</packaging>

WEB-INF WAR文件里:

enter image description here

任何想法,为什么我无法访问test.html?

+1

将'test.html'从'public'移动到'static'。如果使用ThymeLeaf,请将其移至“src/main/resource/templates”。 – Andreas

+0

java和maven标签在这里相关吗? – nullpointer

+0

嗨,我把它移动到静态文件夹,但仍然404。 –

回答

0

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

层级是的src /主/资源/静态/ index.html的

+0

嗨,我把它移动到静态文件夹,但仍然得到404 –

0

现在,你要保持你的资源到未在

src-> main-> java

资源文件夹默认情况下,春季启动正在搜索的.html文件是乌德目录:

src-> main-> resources-> templates 

,我可以看到你是说你把你进入:

src-> main-> JAVA-> resources 

哪项是错误的。

简单:

enter image description here

保持你的控制器,服务,资料库等进入java文件夹,并保持你的资源投入到resources之一。你可以在css,fonts,img,jstemplates文件夹中保留htmlsstatic文件夹。

+0

嗨谢谢,但事实并非如此。我放在src-> main-> java我的java类和使用没有spring-mvc的球衣。我也尝试将我的.html文件放在src-> main - > resources - >模板下,但仍然获得404。我只能在webapp文件夹下访问我的.html文件。 –