Using Spring 3.0.2.RELEASE. I’m having 2 Controllers in package com.myCompany. The Controllers are activated via Component-scan
<context:component-scan base-package="com.myCompany" />
then I’m having a interceptor bind to the 2 controllers via
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list>
<ref bean="myInterceptor"/>
</list>
</property>
</bean>
How can i bind the interceptor to only one specific Controller or to only certain methods inside a Controller?
Background: I want to inspect the URL that it contains certain parameters
When you inject interceptors into a
HandlerMappingbean, those interceptors apply to every handler mapped by thatHandlerMapping. That was fine in the pre-annotation days, since you’d just have configure multipleHandlerMappingbeans. However, with annotations, we tend to have a singleDefaultAnnotationHandlerMappingthat maps everything, so this model doesn’t work.The solution is to use
<mvc:interceptors>, where you explicitly map paths to interceptor beans. See the docs, and this example: