【问题标题】:WebJars doesn't work with Tomcat7 + SpringMVC + Sitemesh3WebJars 不适用于 Tomcat 7 + Spring MVC + Sitemesh 3
【发布时间】:2014-05-05 10:45:12
【问题描述】:

我正在尝试让我的应用程序与在 Tomcat7 上运行的 WebJars 一起工作,但我的 HTML 页面找不到 CSS/JS 文件。

我已经将 web.xml 更改为 v3.0 以及项目的各个方面(在 Eclipse 中)。还检查了 tge 容器中的 web.xml,它也已经配置为 v3.0。

由于我使用的是SpringMVC,所以我做了官方文档中描述的配置:

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

在我的“sitemesh3.xml”文件中,我已经为文件夹“resources”配置了一个排除项:

<?xml version="1.0" encoding="UTF-8"?>

<sitemesh>
    <mapping path="/*" decorator="/resources/decorator.html"/>
    <mapping path="/resources/*" exclue="true"/>

    <content-processor>
        <tag-rule-bundle class="org.sitemesh.content.tagrules.html.DivExtractingTagRuleBundle" />
    </content-processor>
</sitemesh>

在我的“decotator.html”文件中,我试图通过这种方式访问​​ JS:

<script src="/webjars/select2/select2.js"></script>

<script src="../webjars/select2/select2.js"></script>

在我的“pom.xml”文件中正确添加了依赖:

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>select2</artifactId>
    <version>3.4.5</version>
</dependency>

在我看来,Tomcat7 将应用程序部署为 servlet 版本 2.5,一旦 select2.jar 中的文件没有被公开。

有人知道我是否需要配置更多东西吗?你能看出什么不对吗?

【问题讨论】:

  • 问题很可能是您没有在 URL 路径中包含上下文。它通常是您的 WAR 文件的名称,减去“.war”部分。您可以获取 URL,包括正确的上下文,但使用 Spring &lt;spring:url&gt; 标记。标签的 Javadoc:docs.spring.io/spring/docs/3.0.x/api/org/springframework/web/…
  • @CodeChimp,我认为这不是问题所在。看一下找不到文件的网址:localhost:8080/myproject/webjars/select2/select2.js你怎么看?
  • 你可以尝试一些东西吗?首先,我认为 Spring 会在启动时记录它的映射。它可能需要您打开“org.springframework.http”和“org.springframework.web”的调试。我也会尝试在没有“webjar”的情况下点击 URL。只需localhose:8080/myproject/select2/select2.js

标签: spring-mvc tomcat7 sitemesh webjars


【解决方案1】:

两种可能的想法:

有错别字:

<mapping path="/resources/*" exclue="true"/>

应该是exclude 而不是exclue

也许您的sitemesh3.xml 排除在:

<mapping path="/webjars/*" exclude="true"/>

【讨论】:

    猜你喜欢
    • 2017-05-24
    • 1970-01-01
    • 2013-01-24
    • 2011-07-15
    • 1970-01-01
    • 2016-07-15
    • 1970-01-01
    • 1970-01-01
    • 2018-03-18
    相关资源
    最近更新 更多