这是我的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
中的文件或排除mappins中的其他路径时,例如/style/style.css
,拦截器代码仍在运行。即使我将配置更改为<exclude-mapping path="/style/*" />
,问题仍然存在。
如何设置配置文件让<exclude-mapping>
有效?
答案 0 :(得分:0)
我找到了解决方案。
正如what gamerkore said in About mvc:intercepter,how to set excluded path所说,spring在版本3.2中添加了这个功能(我的项目使用了ver.3.1.1.RELEASE)。更新spring版本后我可以工作(我将其更新为版本4.2.0.RELEASE)