5

As we know, we can config an interceptor like that:

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

My question, how to configure excluded path?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Hailei Zhang
  • 63
  • 1
  • 1
  • 4
  • please use comments rather than editing my answer. As for your question - make such a property on your custom intercepetor (one that extends the OSIV interceptor) – Bozho Apr 22 '11 at 17:05

2 Answers2

10

Since Spring 3.2 they added that feature.

See this example from 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's the link to the doc

gamerkore
  • 1,105
  • 1
  • 11
  • 16
  • 3
    how to do it in Spring 4 ?? I'm getting this error: cvc-complex-type.2.4.a: Invalid content was found starting with element 'mapping'. One of '{"http:// www.springframework.org/schema/beans":bean, "http://www.springframework.org/schema/beans":ref, "http:// www.springframework.org/schema/mvc":interceptor}' is expected – Chris Sim Feb 24 '16 at 14:05
  • @ChrisSim you have to had the prefix `mvc:` to `mapping` and `exclude-mapping` tags. – xonya Dec 10 '18 at 15:05
0

I don't think you can declaratively. But within the interceptor you can add an if(..) and verify whether the request uri should be excluded. You can set the exclusion paths as a list property in the interceptor xml definition.

For that you will have to extend the OSIV interceptor and add that custom logic & exclusion list property.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140