Spirng boot版2.5.0集成quartz定时任务使用@ApiLog异常,统一异常拦截不到quartz中抛出的异常

Java 未结 2 2519
gg
gg 2020-05-28 13:55

一、该问题的重现步骤是什么?

问题1.   Spirng boot版2.5.0集成quartz定时任务使用@ApiLog异常,怎么处理?

问题2.  统一异常拦截不到quartz中抛出的异常,也拦截不到非Controller及service抛出的异常



二、你期待的结果是什么?实际看到的又是什么?

    实际上目前会自动拦截Controller及service层抛出的异常入库,期望全局统一异常拦截到quartz定时任务中的异常并自动入库,也期望程序在任何地方抛出的异常都能入库,不局限于Controller及service层。


三、你正在使用的是什么产品,什么版本?在什么操作系统上?

   Spirng boot版2.5.0.RELEASE      windows

四、请提供详细的错误堆栈信息,这很重要。


2020-05-28 13:38:20.704 ERROR 49936 --- [eduler_Worker-2] c.sinoif.quartz.util.AbstractQuartzJob   : 任务执行异常  - :
java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_201]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_201]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_201]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_201]
at com.sinoif.quartz.util.JobInvokeUtil.invokeMethod(JobInvokeUtil.java:64) ~[classes/:na]
at com.sinoif.quartz.util.JobInvokeUtil.invokeMethod(JobInvokeUtil.java:36) ~[classes/:na]
at com.sinoif.quartz.util.QuartzDisallowConcurrentExecution.doExecute(QuartzDisallowConcurrentExecution.java:20) ~[classes/:na]
at com.sinoif.quartz.util.AbstractQuartzJob.execute(AbstractQuartzJob.java:43) ~[classes/:na]
at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [quartz-2.3.2.jar:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.3.2.jar:na]
Caused by: java.lang.NullPointerException: null
at org.springblade.core.log.utils.LogAbstractUtil.addRequestInfoToLog(LogAbstractUtil.java:46) ~[classes/:na]
at org.springblade.core.log.publisher.ApiLogPublisher.publishEvent(ApiLogPublisher.java:48) ~[classes/:na]
at org.springblade.core.log.aspect.ApiLogAspect.around(ApiLogAspect.java:49) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_201]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_201]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_201]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_201]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) ~[spring-aop-5.1.14.RELEASE.jar:5.1.14.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633) ~[spring-aop-5.1.14.RELEASE.jar:5.1.14.RELEASE]
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) ~[spring-aop-5.1.14.RELEASE.jar:5.1.14.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.1.14.RELEASE.jar:5.1.14.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.1.14.RELEASE.jar:5.1.14.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.14.RELEASE.jar:5.1.14.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) ~[spring-aop-5.1.14.RELEASE.jar:5.1.14.RELEASE]
at com.sinoif.base.tasks.ExceptionEmailTask$$EnhancerBySpringCGLIB$$538a9d00.sendExceptionMsg() ~[classes/:na]
... 10 common frames omitted

五、若有更多详细信息,请在下面提供。

2条回答
  •  smallchill
    smallchill (楼主)
    2020-05-28 14:58

    quartz 是异步的,没有请求,没法获取到request,所以不能用这个方法。

    至于你的问题可以这么百度:quartz全局异常处理

    作者追问:2020-05-28 14:58

    如果没有请求,服务端抛出的异常也希望全局拦截到并入库,怎么库处理? 参考 ErrorLogPublisher.publishEvent方法自己写套针对没有请求抛出的异常处理逻辑?

提交回复