java - 通过 WebJars 将 Bootstrap 包含到 SpringMVC 项目的问题

标签 java eclipse maven twitter-bootstrap spring-mvc

我尝试在我的 SpringMVC 项目中使用 Bootstrap: link to GitHub repo

不幸的是,CSS 文件不可见。浏览器在控制台中抛出这样的错误:

获取 http://localhost:8080/finager/webjars/jquery/2.0.3/jquery.js 404(未找到)

我认为 pom.xml 具有正确的配置,因为我能够在 Eclipse 中的 Java 资源 -> 库 -> Maven 依赖项下查看包含的 WebJar(Bootstrap 和 JQuery)。我还在 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 开发的新手,所以我花了一整天的时间,所以非常感谢任何帮助。提前致谢!

最佳答案

以这种方式指定位置将为您解决问题(注意 classpath:):

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

此外,您的路径中似乎有 jquery 1.8.2,因此 url 应遵循以下几行:

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

这是一个很好的引用 - https://spring.io/blog/2014/01/03/utilizing-webjars-in-spring-boot

关于java - 通过 WebJars 将 Bootstrap 包含到 SpringMVC 项目的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20940881/

相关文章:

java - 如何断言 TestNG java 没有抛出异常

android - 当对 phonegap 应用程序进行更改时,Eclipse 不更新 apk

eclipse - 通过 Tomcat 调试 Eclipse 时如何更改实例

java - Spring 未正确实例化对象。为什么?

java - Spring Boot 自动 JSON 到 Controller 中的对象

java - Spring AOP : how to get the annotations of the adviced method

java - Eclipse 项目未添加到构建路径

java - 带有 Hibernate 4.2 错误 : setCharacterStream(ILjava/io/Reader;J)V is abstract 的 C3p0

tomcat - 如何使用 maven :run with my custom configuration file? 运行 Tomcat

java - 将 Lettuce 与 RedisTemplate 一起使用会抛出异常