问题描述
我尝试使用AOP登录CompletableFuture
控制器。 @Before
的建议正常。但是使用@AfterReturning
在异常情况下无法正常工作。我还尝试了@AfterThrowing
,但该方法也不起作用。发生异常时,我的@AfterReturning
的建议也不会触发,并且永远不会到达@AfterThrowing
。
在这种情况下,如何使用带有例外的AOP建议?
JController:
@RestController
public class JController extends BaseExceptionHandler {
@GetMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public CompletableFuture<BaseResponse> search() {
final CompletableFuture result = asyncProcessor.process(request);
return result;
}
}
BaseExceptionHandler:
public class BaseExceptionHandler {
@ExceptionHandler(Exception.class)
public ResponseEntity handleException(final Exception exception) {
return new ResponseEntity<>(new ErrorResponse(Message.INTERNAL_SERVER_ERROR,StatusCode.UNKNOWN_ERROR),HttpStatus.INTERNAL_SERVER_ERROR);
}
}
AOP类
@AfterReturning(value = "execution(* com.xxx.xxx.controller.*.*(..))",returning = "result")
public void outgoingSuccess(final JoinPoint joinPoint,final CompletableFuture result) {
LOGGER.debug("After Returning method: " + joinPoint.getTarget().getClass().getSimpleName());
}
@AfterThrowing("execution(* com.xxx.xxx.controller.*.*(..))")
public void outgoingError(final JoinPoint joinPoint) {
LOGGER.debug("After Throwing method: " + joinPoint.getTarget().getClass().getSimpleName());
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)