cannot be cast to org.springframework.web.method.HandlerMethod 解决方法

用annotation做权限控制的时候,在拦截器里转时

    @Override  

    public boolean preHandle(HttpServletRequest request,  

            HttpServletResponse response, Object handler) throws Exception {  

 HandlerMethod handler2 = (HandlerMethod) handler;

//NotAuth notAuth = handler2.getMethodAnnotation(NotAuth.class); 

 

报错

java.lang.ClassCastException: com.*.*Controller cannot be cast to org.springframework.web.method.HandlerMethod

意思是无法转换成HandlerMethod对象

解决办法:

<bean  class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"> 
替换 
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/> 
因为DefaultAnnotationHandlerMapping只能返回Controller对象,不会映射到Controller中的方法级别

 

参考:http://chenzhou123520.iteye.com/blog/1702563

 

你可能感兴趣的:(springframework)