2014-01-06 27 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