如何设置“排除映射”在Spring MVC拦截器



下面是我的XML配置:

<?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:beans="http://www.springframework.org/schema/beans"
     ...
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        ... ">
    <resources mapping="/resources/**" location="/resources/" />
    <resources mapping="/style/**" location="/resources/style/" />
    <resources mapping="/script/**" location="/resources/script/" />
    <resources mapping="/images/**" location="/resources/images/" />
    <resources mapping="/uploaded/**" location="/resources/uploaded/" />
    <interceptors>
        <interceptor>
            <mapping path="/**" />
            <exclude-mapping path="/style/**" />
            <exclude-mapping path="/script/**" />
            <exclude-mapping path="/images/**" />
            <exclude-mapping path="/uploaded/**" />
            <exclude-mapping path="/resources/**" />
            <beans:bean class="com.example.MyInterceptor" />
        </interceptor>
    </interceptors>
</beans:beans>

我的问题是,当我浏览一个文件在/style或其他路径排除映射,如/style/style.css,拦截器代码仍然运行。即使我将配置更改为<exclude-mapping path="/style/*" />,问题仍然发生。

如何设置配置文件使<exclude-mapping>工作?

我找到了解决方案。

正如gamerkore在关于mvc:intercepter,如何设置排除路径中所说的,spring在3.2版本中添加了这个功能(我的项目已经使用了ver。3.1.1.RELEASE)。它可以在更新spring版本后工作(我更新到ver。4.2.0.RELEASE)

最新更新