About mvc: intercepter how to set an excluded path

As we know, we can configure such an interceptor:

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

My question is how to configure the excluded path?

+5
source share
2 answers

I do not think you can declaratively. But inside the interceptor you can add if(..)and check if uri request should be excluded. You can set exception paths as a list property in the xml interceptor definition.

To do this, you will need to extend the OSIV interceptor and add this custom logic property and exceptions.

0
source

Since Spring 3.2, they have added this feature.

See this example in the Spring documentation:

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

Here is a link to the document

+10

All Articles