mvc:排除映射抛出错误,同时排除弹簧拦截器的url

时间:2016-01-18 09:40:05

标签: spring-mvc

通过使用弹簧拦截器我想拦截除了一些以外的所有请求,所以我想要排除它。我使用 mvc:exclude-mapping 获得了解决方案,但它显示错误。

<?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:exclude mapping tag抛出错误,即

cvc-complex-type.2.4.a:从元素'mvc:exclude-mapping'开始发现无效内容。其中一个'{“http://www.springframework.org/schema/mvc”:mapping,“http://www.springframework.org/schema/beans”:bean}'是  预期

1 个答案:

答案 0 :(得分: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