java.lang.ClassCastException: org.springframework.web.servlet.resource.ResourceHttpRequestHandler cannot be cast to org.springframework.web.method.HandlerMethod
拦截器中的preHandler方法部分代码如下:
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler) throws Exception {
//此处报错
HandlerMethod handlerMethod = (HandlerMethod) handler;
}
解决办法, instanceof关键字进行判断。
HandlerMethod handlerMethod = null;
//获取执行方法上的注解
if(handler instanceof HandlerMethod){
handlerMethod = (HandlerMethod) handler;
}else{
return true;
}