2016-12-15 56 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文件。 –