2014-01-06 46 views
3

我試着在我的項目用SpringMVC使用引導: link to GitHub repo問題通過WebJars包括引導到項目用SpringMVC

不幸的是,CSS文件是不可見的。該瀏覽器引發錯誤控制檯是這樣的:

GET http://localhost:8080/finager/webjars/jquery/2.0.3/jquery.js 404 (Not Found)

我想的pom.xml有適當的配置,因爲我可以在Eclipse中查看在Java Resources包括WebJars(引導和JQuery) - >庫 - > Maven的依賴。我還設置路徑是這樣的(最後一行)的servlet-context.xml中:

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> 
<resources mapping="/resources/**" location="/resources/" /> 
<resources mapping="/webjars/**" location="/META-INF/resources/webjars/"/> 

我覺得這條線是正確的,因爲Tomcat的不再說,它不知道如何處理的請求開始「/ webjars /。我找到的所有教程都只列出了這些步驟,並且我無法在Internet上找到任何有用的信息。我花了整整一天的時間,因爲我是Spring開發的新手,所以任何幫助都會得到很大的讚賞。提前致謝!

回答

6

指定位置,這樣一來會解決這個問題你(注意classpath:):

<resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/> 

而且,你似乎有jQuery的1.8.2在您的路徑,所以網址應該是沿着這些線路:

http://localhost:8080/finager/webjars/jquery/1.8.2/jquery.js 

這裏是一個很好的參考 - https://spring.io/blog/2014/01/03/utilizing-webjars-in-spring-boot

+0

這和檢查解決了該問題引導版本!謝謝! –

+0

當使用Spring Boot構建Spring MVC應用程序時,Spring Boot會自動爲您添加「/ webjars/**」資源配置。 –

+0

可以通過代碼添加: .setCachePeriod(604800);其中, – gkephorus