Announcement Announcement Module
Collapse
No announcement yet.
HandlerInceptor not working in Spring 3.1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HandlerInceptor not working in Spring 3.1

    Using Spring 3.1.RELEASE

    Hi,

    As per the documentation defining handlerInceptor as follows should call the registered interceptor before, after, and afterCompletion. However, when I define the interceptor it is never called.

    Code:
            <bean id="myInterceptor" class="com.sample.MyInterceptor" />
    
    	<bean id="handlerMapping"
    		class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    		<property name="interceptors">
    			<list>
    				<ref bean="myInterceptor" />
    			</list>
    		</property>
    	</bean> 
    
    
    @Controller
    @RequestMapping("/example/login")
    public class TestController {
            //........
    }
    
    public class MyInterceptor implements HandlerInterceptor{
         // all methods implemented....	
    }
    However, if I rewrite my controller using old fashion way i.e. by extending AbstractController and defining SimpleUrlHandlerMapping the interceptor works fine.

    Code:
    	<bean id="handlerMapping"
    		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		 
    		<property name="interceptors">
    			<list>
    				<ref bean="myInterceptor" />
    			</list>
    		</property>
    		<property name="mappings">
    			<props>
    				<prop key="/sample/login">testController</prop>
    			</props>
    		</property>
    	</bean> 
    
    
    public class TestController extends AbstractController{
            // implemented methods...
    }
    Any ideas??? why the interceptors defined on DefaultAnnotationHandlerMapping are not working?

  • #2
    Use the mvc namespace to register interceptors... I suspect you have mvc:annotation-driven which in 3.1 registers the RequestMappingHandlerMapping to map urls not the DefaultAnnotationHandlerMapping. Also if you have both HandlerMappings defined you might run into problems with duplicate mappings etc.

    Comment


    • #3
      Thank you for the hint, Martin. It works using namespace to register interceptors.

      Comment

      Working...
      X