2016-01-18 77 views
0

通過使用彈簧攔截器,我想攔截除一些以外的所有請求,所以我想排除它。我通過使用mvc:exclude-mapping得到了解決方案,但它顯示錯誤。mvc:排除映射拋出錯誤,同時排除彈簧攔截器的url

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

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


    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> 

    <!-- Enables the Spring MVC @Controller programming model --> 
    <annotation-driven /> 

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving 
     up static resources in the ${webappRoot}/resources directory --> 
    <resources mapping="/resources/**" location="/resources/" /> 

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
     in the /WEB-INF/views directory --> 
    <beans:bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <beans:property name="prefix" value="/WEB-INF/views/" /> 
     <beans:property name="suffix" value=".jsp" /> 
    </beans:bean> 

    <context:component-scan base-package="test.org.reg" /> 

    <mvc:interceptors> 
     <beans:bean 
      class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
      <beans:property name="paramName" value="lang" /> 
     </beans:bean> 


<mvc:interceptor> 
      <!-- <mvc:mapping path="/" /> --> 
      <mvc:mapping path="/**" /> 
      ***<mvc:exclude-mapping path="/test/**" />*** 
      <beans:bean class="a.b.c.MyInterceptor"></beans:bean> 
     </mvc:interceptor> 
</mvc:interceptors> 
    <beans:bean 
     class="org.springframework.web.multipart.commons.CommonsMultipartResolver" 
     id="multipartResolver" /> 
    <beans:import resource="classpath:DI/*.xml" /> 


</beans:beans> 

在這裏MVC:排除映射標籤拋出錯誤即

CVC-複雜type.2.4.a:無效的含量被發現與一個元素開始 'MVC:排除映射'。 「{」http://www.springframework.org/schema/mvc「:映射」,http://www.springframework.org/schema/beans「:bean}'之一是 預計。

回答

0

確保xsd指向3.2。

xsi:schemaLocation="springframework.org/schema/beans springframework.org/schema/beans/spring-beans-3.2.xsd springframework.org/schema/context springframework.org/schema/context/spring-context-3.2.xsd springframework.org/schema/mvc springframework.org/schema/mvc/spring-mvc-3.2.xsd"> 

Spring自Spring 3.2以來增加了該功能。這裏是文檔的link