【发布时间】:2018-08-28 22:03:19
【问题描述】:
我有一个 MQ Spring Boot PaaS 应用程序,我需要通过一个通用异常处理程序类 (GlobalExceptionHandler) 实现异常处理。我的 PaaS 应用程序从源队列接收消息,通过 spring jpa 执行一些数据库操作并将响应写回目标队列。
我需要通过 GlobalExceptionHandler 类处理所有的数据库 RuntimeException、自定义业务异常和其他检查异常。
我的 GlobalExceptionHandler 将为每个异常定义处理程序(方法)。在我的处理程序中,我将首先记录异常,然后创建一个 [error code, desc],然后我需要将其返回到主流程。
我的应用程序中没有任何控制器。所以我认为,我不能使用@ControllerAdvice。目前我正在使用 spring AOP @AfterThrowing,如下所示,但我无法从处理程序返回 [code, desc]。
@AfterThrowing(pointcut = "execution(* com.abc.xyz.service..*(..)) ",
throwing = "dataNotFoundException")
public void handleDataNotFoundException(DataNotFoundException dataNotFoundException) {
LOGGER.info("Info : " + dataNotFoundException.getMessage());
// code, desc need to create here and send it back to calling place.
// I need to change the return type here from void.
}
谁能指导我在这里实现异常处理。
【问题讨论】:
标签: spring spring-boot exception-handling spring-aop