0
@Before("within(control..*)")
public void before(JoinPoint joinPoint) {
    // Set Process Start Time
    startTime = System.currentTimeMillis();
    Object[] arguments = joinPoint.getArgs();
    if (arguments != null && arguments.length > 0) {
        System.out.println("data:" + arguments[0]);
    }
}

我尝试使用@aspect输出请求体,但是如果使用@valid时参数错误,spring boot会抛出MethodArgumentNotValidException,并且不会输出@aspect日志。

即使发生异常,如何在服务器收到http请求时输出json请求正文?

4

1 回答 1

0

我通过使用@AfterThrowing 解决了这个问题。

@AfterThrowing(pointcut = "controllerInvocation()", throwing = "exception")
public void afterThrowing(JoinPoint joinPoint, Exception exception) {
    this.outputResponseLog(joinPoint, exception);
}
于 2016-06-07T05:43:13.687 回答