关于mvc:intercepter,如何设置排除路径

Hai*_*ang 5 spring spring-mvc

我们知道,我们可以像这样配置一个拦截器:

 <mvc:interceptor>
        <mvc:mapping path="/outfit/**" />
        <bean class="OpenSessionInViewInterceptor">
            <property name="sessionFactory">
                <ref bean="sessionFactory" />
            </property>
        </bean>
Run Code Online (Sandbox Code Playgroud)

我的问题,如何配置排除路径?

gam*_*ore 10

从Spring 3.2开始,他们添加了该功能.

从Spring文档中查看此示例:

<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
<mvc:interceptor>
    <mapping path="/**"/>
    <exclude-mapping path="/admin/**"/>
    <bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor" />
</mvc:interceptor>
<mvc:interceptor>
    <mapping path="/secure/*"/>
    <bean class="org.example.SecurityInterceptor" />
</mvc:interceptor>
Run Code Online (Sandbox Code Playgroud)

这是doc 的链接

  • 春天4怎么做?我收到此错误:cvc-complex-type.2.4.a:从元素'mapping'开始发现无效内容.其中一个'{"http:// www.springframework.org/schema/beans":bean,"http://www.springframework.org/schema/beans":ref,"http:// www.springframework.org/schema/mvc":interceptor}"是预期的 (3认同)

Boz*_*zho 0

我认为你不能声明。但在拦截器中,您可以添加if(..)并验证是否应排除请求 uri。您可以将排除路径设置为拦截器 xml 定义中的列表属性。

为此,您必须扩展 OSIV 拦截器并添加自定义逻辑和排除列表属性。