Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 关于mvc:拦截器,如何设置排除路径_Spring_Spring Mvc - Fatal编程技术网

Spring 关于mvc:拦截器,如何设置排除路径

Spring 关于mvc:拦截器,如何设置排除路径,spring,spring-mvc,Spring,Spring Mvc,我们知道,我们可以这样配置拦截器: <mvc:interceptor> <mvc:mapping path="/outfit/**" /> <bean class="OpenSessionInViewInterceptor"> <property name="sessionFactory"> <ref bean="sessionFactory" />

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

 <mvc:interceptor>
        <mvc:mapping path="/outfit/**" />
        <bean class="OpenSessionInViewInterceptor">
            <property name="sessionFactory">
                <ref bean="sessionFactory" />
            </property>
        </bean>


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

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


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

自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>


以下是对文档的建议

请使用注释,而不是编辑我的答案。至于你的问题-在你的自定义interceptor(扩展OSIV拦截器的)上创建这样一个属性,非常抱歉!我很抱歉将我的内容添加到您的答案中。扩展OSIV是合适的。谢谢!同时,我找到了另一种方法。添加多个映射路径来指定拦截器,如下所示,如何在Spring4中实现它??我收到以下错误:cvc复杂类型。2.4.a:发现以元素“映射”开头的无效内容。其中一个“{”http://www.springframework.org/schema/beans:bean“,“http://www.springframework.org/schema/mvc:interceptor}”是expected@ChrisSim您必须具有前缀
mvc:
to
mapping
exclude mapping
标记。