2015-12-02 34 views
0

我有我的index.html thymeleaf頁面來了,但我在頁面上引用的CSS沒有被發現。引用一個.css文件與百里香在春天mvc使用th:href

<link href="../css/bootstrap.min.css" rel="stylesheet" th:href="@{/css/bootstrap.min.css}" type="text/css"/> 

這裏是部署WAR的樣子在Tomcat中: enter image description here

中的index.html是在模板文件夾。

但我收到以下錯誤在Chrome控制檯:

GET http://localhost:8080/pocApp/css/bootstrap.min.css 404(未找到)

如果我能得到index.html頁面精細爲什麼不能thymeleaf servlet找到那個文件?我試圖將整個css目錄粘貼到目錄結構中的各個位置,例如在WEB-INF和WEB-INF/classes中,但沒有運氣。

回答

0

這個網站正在迅速成爲我的橡皮鴨,因爲這是我回答自己的第二個問題。

在我的春節,4 Java的配置我有這樣的:

public class SpringWebConfig extends WebMvcConfigurerAdapter { 

@Override 
public void addResourceHandlers(ResourceHandlerRegistry registry) { 
    registry.addResourceHandler("/resources/**") 
      .addResourceLocations("/resources/"); 
} 

所以我不得不調整自己的目錄,並更改樣式表的URL。

新的目錄結構: enter image description here

從我的index.html

<link href="../resources/css/bootstrap.min.css" rel="stylesheet" th:href="@{/resources/css/bootstrap.min.css}" type="text/css"/> 
+0

歡迎來到我的世界,新的代碼片段。我只是假設我知道比大多數,因爲我不問很多問題,當我這樣做時,我回答自己。 :( – Switch