【问题标题】:Webjars In Spring Boot - Javascript not loadingSpring Boot中的Webjars - Javascript未加载
【发布时间】:2014-11-13 03:49:03
【问题描述】:

我正在尝试使用 Webjar 将 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 寻找资源的理解,我认为它应该找到这个。

有人看到这种行为吗?关于如何解决它的任何提示?

【问题讨论】:

    标签: spring spring-boot webjars


    【解决方案1】:

    这对我有用:

    <script src="/webjars/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>
    

    您确定它实际上在运行时位于类路径中吗?您是否正在运行具有上下文路径的应用程序(即不从“/”提供资产)?

    【讨论】:

    • 你是对的。这似乎是我的 Eclipse 项目与我的依赖项不同步的问题。谢谢。
    • 我注意到type="text/javascript" 对于让它为我工作至关重要。
    猜你喜欢
    • 2015-12-17
    • 2019-10-30
    • 2019-04-26
    • 2019-01-21
    • 2018-08-15
    • 2018-06-19
    • 2016-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多