我正在尝试使用 Webjars 将 jQuery 添加到我的启动应用程序。我从本教程中得到灵感:
http://spring.io/blog/2014/01/03/utilizing-webjars-in-spring-boot
在我的 pom.xml 中,我添加了:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.1.1</version>
</dependency>
在我的 html 文件中(使用 ThymeLeaf 作为我的模板引擎 - 不确定这是否重要)我有以下内容:
<script src="webjars/jquery/2.1.1/jquery.min.js"></script>
该文件不加载。我已经尝试了 src="webjars...."和 src="/webjars..."。
我可以在我的项目中列出的 Maven 依赖项中看到 jar。当我探索这个 jar 时,我可以看到 META-INF/resources/webjars/jquery/2.1.1/jquery.min.js。根据我对 Boot 查找资源的理解,我认为它应该找到这个。
有人看到这种行为吗?有关如何解决问题的任何提示?
最佳答案
这对我有用:
<script src="/webjars/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>
您确定它实际上在运行时位于类路径上吗?您是否正在运行带有上下文路径的应用程序(即不提供来自“/”的 Assets )?
关于spring - Spring Boot 中的 Webjars - Javascript 未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25918850/