2014-03-26 25 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"/>