[英]Spring mvc interceptor exception
My project is baded on spring mvc, and I wrote a interceptor to intercept request, I want to get parametrts from request, the follows is my code: 我的项目是在spring mvc上加入的,我编写了一个截取拦截请求的拦截器,我想从请求获取参数,以下是我的代码:
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
HandlerMethod maControl = (HandlerMethod) handler;
Method pmrResolver = (Method) maControl.getMethod();
String methodName = pmrResolver.getName();
....
}
but now it throws a exception: 但现在它引发了一个异常:
java.lang.ClassCastException: org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler cannot be cast to org.springframework.web.method.HandlerMethod
What is the cause of the Exception? 异常的原因是什么?
It simply means that handler
isn't an instance of HandlerMethod
, so the cast fails. 它只是意味着
handler
不是HandlerMethod
的实例,因此转换失败。 Check before casting as follow: 铸造前检查如下:
if (handler instanceof HandlerMethod) {
HandlerMethod maControl = (HandlerMethod) handler;
Method pmrResolver = (Method) maControl.getMethod();
String methodName = pmrResolver.getName();
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.