開發一個基于注解的登入攔截器,遇到攔截器隻能攔截controller不能攔截到具體的方法名,這樣攔截器就完全沒用,經過仔細摸索,DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter并不支援攔截方法,發現隻有3.1版本後才支援,而且需要使用RequestMappingHandlerMapping 和 RequestMappingHandlerAdapter來替換 ,也可以直接通過引入annotation-driven使用,然後你就會發現攔截器攔截方法名了,也就可以掃描到注解了
一下是幾個關鍵版本的變更資訊
spring2.5後
需要通過處理器映射DefaultAnnotationHandlerMapping和處理器擴充卡AnnotationMethodHandlerAdapter來開啟支援@Controller 和 @RequestMapping注解的處理器。
Spring3.1使用
新的HandlerMapping 和 HandlerAdapter來支援@Contoller和@RequestMapping注解處理器。
新的@Contoller和@RequestMapping注解支援類:處理器映射RequestMappingHandlerMapping 和 處理器擴充卡RequestMappingHandlerAdapter組合來代替Spring2.5開始的處理器映射DefaultAnnotationHandlerMapping和處理器擴充卡AnnotationMethodHandlerAdapter,提供更多的擴充點。
在spring mvc 3.1中,對應變更為
DefaultAnnotationHandlerMapping -> org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
AnnotationMethodHandlerAdapter -> org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
AnnotationMethodHandlerExceptionResolver -> ExceptionHandlerExceptionResolver
以上都在使用了annotation-driven後自動注冊