具有CompletableFuture的Spring-boot AOP建议

问题描述

我尝试使用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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...