2014-03-26 23 views
2

我试图让我的应用程序能够在运行在Tomcat7上的WebJars上运行,但是CSS/JS文件没有被我的HTML页面找到。WebJars不支持Tomcat7 + SpringMVC + Sitemesh3

我已经将web.xml更改为v3.0以及项目的构面(Eclipse内部)。还检查了来自tge容器的web.xml,该配置文件也已配置为v3.0。

,因为我用SpringMVC使用,我做了描述到官方文档配置:

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

在我的“sitemesh3.xml”的文件,我已经配置排除到文件夹“资源”:

<?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没有公开。

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

+0

最有可能的问题是你是不是包括在URL路径的上下文。它通常是WAR文件的名称,减去“.war”部分。您可以获取URL,包括正确的上下文,但使用Spring''标签。 Javadoc的标签:http://docs.spring.io/spring/docs/3.0.x/api/org/springframework/web/servlet/tags/UrlTag.html – CodeChimp

+0

@CodeChimp,我不认为这是问题。看看网址所在的文件未找到: 的http://本地主机:8080/MyProject的/ webjars /选择2/select2.js 你觉得呢? – Pmt

+0

你可以尝试几件事吗?首先,我认为Spring会记录启动时的映射。它可能需要你打开'org.springframework.http'和'org.springframework.web'的调试。我也会尝试在那里没有'webjar'的网址。只要执行'localhose:8080/myproject/select2/select2.js'。 – CodeChimp

回答

2

两种可能的想法:

有一个错字:

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

大概应该是excludeexclue

也许你sitemesh3.xml排除是:

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