bind Spring HandlerInterceptor only to one controller

后端 未结 1 1274
你的背包
你的背包 2020-12-14 03:14

Using Spring 3.0.2.RELEASE. I\'m having 2 Controllers in package com.myCompany. The Controllers are activated via Component-scan



        
1条回答
  •  情书的邮戳
    2020-12-14 03:50

    When you inject interceptors into a HandlerMapping bean, those interceptors apply to every handler mapped by that HandlerMapping. That was fine in the pre-annotation days, since you'd just have configure multiple HandlerMapping beans. However, with annotations, we tend to have a single DefaultAnnotationHandlerMapping that maps everything, so this model doesn't work.

    The solution is to use , where you explicitly map paths to interceptor beans. See the docs, and this example:

    
        
            
            
        
    
    

    0 讨论(0)
提交回复
热议问题