HandlerExceptionResolver 全局异常拦截器 报错

3-Dec-2017 15:49:09.225 SEVERE [http-nio-80-exec-30] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [mvc-dispatcher] in context with path [] threw exception [Request processing failed; nested exception is java.lang.ClassCastException: org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler cannot be cast to org.springframework.web.method.HandlerMethod] with root cause
	 java.lang.ClassCastException: org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler cannot be cast to org.springframework.web.method.HandlerMethod
		at interceptor.GlobalExceptionResolver.resolveException(GlobalExceptionResolver.java:25)
		at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1222)
		at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1034)
		at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984)
		at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
		at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
		at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
		at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
		at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
		at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
		at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
		at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
		at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
		at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
		at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
		at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
		at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
		at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
		at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
		at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
		at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
		at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
		at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
		at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
		at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
		at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
		at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
		at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
		at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
		at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
		at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
		at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
		at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
		at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
		at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
		at java.lang.Thread.run(Thread.java:748)

报错原因: 后台的异常拦截器对handel类型转换失败造成的:

解决办法在handel转换前进行判断:

 if(o instanceof HandlerMethod){
      String methodName = ((HandlerMethod) o).getMethod().getName();
      String className  = ((HandlerMethod)o).getBeanType().getSimpleName();
      logger.error("异常信息>>>>>ClassName:"+className+".....method:"+methodName+".....",e);
 }

  

  

时间: 2024-10-11 13:26:32

HandlerExceptionResolver 全局异常拦截器 报错的相关文章

Asp.Netcore使用Filter来实现接口的全局异常拦截,以及前置拦截和后置拦截

原文链接:https://blog.csdn.net/qq_38762313/article/details/85234594 全局异常拦截器:       解决写每个接口都需要去做容错而添加try{}catch{},有了该异常拦截器后,所有接口都不需要去添加异常处理. 实现方式: 第一步:新建一个类继承 IExceptionFilter,添加 using Microsoft.AspNetCore.Mvc.Filters;该类的名称命名要求是:后缀必须ExceptionFilter,例如:Glo

Java自定义异常类以及异常拦截器

自定义异常类不难,但下面这个方法,它的核心是异常拦截器类. 就算是在分布式系统间进行传递也可以,只要最顶层的服务有这个异常拦截器类(下例是在springmvc项目中) 1.自定义异常类,继承自 RuntimeException,参数只有一个异常错误码 public class BingException extends RuntimeException { private final int code; public BingException(int code) { this.code = c

SQL语句异常导致项目报错

1.错误描述 严重:Exception occurred during processing request:Statement Callback;SQL[   ];OALL8处于不一致状态; nested exception is java.sql.SQLException:OALL8处于不一致状态. java.sql.SQLException:违反协议 Caused by:java.sql.SQLException:OALL8处于不一致状态 2.错误原因 (1)连接Oracle驱动不匹配 (

Android studio 导入Eclipse项目 Vitamio播放器报错

由于Vitamio播放器更新到5.0,需要更新其依赖库,但是坑爹的是,此依赖库是Eclipse项目,导入过程如下: 首先:打开项目配置 进入到以下页面: 如图所示 点击+号 选择import Eclipse ADT Project 接下来一步步next即可 导入后不出意外,一堆的报错,主要是gradle不能被正确配置,看来studio智商有限呀!! 我们来帮帮他, 先看看出了哪些错误: 无法找到这个配置 compileSdkVersion Integer.parseInt(project.AND

拦截器报循环依赖错误

拦截器 @Slf4j @Component public class LcOpPermissionInterceptor extends HandlerInterceptorAdapter { ...... } 将拦截器注入适配器中 @Configuration public class LcOpWebMvcConfigurer extends WebMvcConfigurerAdapter { @Autowired private LcOpPermissionInterceptor lcOpP

springboot全局异常拦截源码解读

在springboot中我们可以通过注解@ControllerAdvice来声明一个异常拦截类,通过@ExceptionHandler获取拦截类抛出来的具体异常类,我们可以通过阅读源码并debug去解读springboot的异常拦截机制. 在了解异常拦截机制之前,我引用他人图片大致介绍下springmvc的大致调用流程 异常拦截处理流程: 1. 首先会调用DispatcherServlet的doDispatch分发请求 2. 通过processDispatchResult方法处理分发结果 3.

NPM全局安装依赖权限报错Error: EACCES: permission denied

最近在安装electron-forge的时候报错如下: ? ~ sudo npm install -g electron-forge npm WARN deprecated [email protected]: [email protected]<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the

SpringMVC + Mybatis + Shiro + ehcache时缓存管理器报错。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroFilter' defined in class path resource [spring/spring-shiro-web.xml]: Cannot resolve reference to bean 'securityManager' while setting bean property 'securit

ie11的DOM管理器报错

IE11 Windows7下F12 DOC资源管理器不能用Exception in window.onload: Error: An error has ocurredJSPlugin.3005------------------Diagnostic:Exception in window.onload: Error: An error has ocurredJSPlugin.3005Stack Trace:Error: An error has ocurredJSPlugin.3005 at