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]);
    }
}

I tried to use @aspect to output tht request body, but if the parameter is wrong when using @valid, spring boot will throw MethodArgumentNotValidException, and @aspect logs will not be output.

How can I output the json request body at the time when server receives a http request even there is an exceptinon happened?

Yuu
  • 1
  • 1
  • 3

1 Answers1

0

I fixed the problem by using @AfterThrowing.

@AfterThrowing(pointcut = "controllerInvocation()", throwing = "exception")
public void afterThrowing(JoinPoint joinPoint, Exception exception) {
    this.outputResponseLog(joinPoint, exception);
}
Yuu
  • 1
  • 1
  • 3