1. 程式人生 > >J2EE for SpringMVC 對映靜態資源獨Js不成功的問題解決

J2EE for SpringMVC 對映靜態資源獨Js不成功的問題解決

剛才博主遇到一個很頭大的問題,靜態資源映射了,路徑語法啥的都沒問題而css和img又能夠對映成功,能夠正常讀取,經過反覆檢查,博主發現是版本跟不上了。

看看博主的配置先:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--本專案把靜態資源放在了WEB-INF的statics目錄下,資源對映如下-->
    <mvc:resources mapping="/css/**" location="/WEB-INF/statics/css/"/>
    <mvc:resources mapping="/js/**" location="/WEB-INF/statics/js/"/>
    <mvc:resources mapping="/img/**" location
="/WEB-INF/statics/img/"/>

問題就處在了schema:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

這樣寫就沒問題了。

關鍵:

http://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

只需要加上-3.0就ok了!