0

I am using aop with spring boot 2.1.1, I have pointcut and advise to log calls and return values of methods annotated with custom annotation @LogAround

@Pointcut("@annotation(x.y.z.LogAround)")
public void logAroundJoinPoint() {}

@Before("logAroundJoinPoint()")
public void logBefore(JoinPoint joinPoint) {
// logging code
}

@AfterReturning(
          pointcut = "logAroundJoinPoint()",
          returning= "result")
     public void logAfterReturning(JoinPoint joinPoint, Object result) {
    //some logging code

     }

This codes logs method calls as expected for methods annotated with @LogAround except when I use on method annotated with @Recover for spring retry!

I have no idea as why this is happening.

One option is to simple log withing the recover method but I would prefer if there is a way to make this work. Any help is appreciated.

I have setup demo code at git_demo_code

Pavan Kumar
  • 462
  • 5
  • 13

1 Answers1

0

Both pieces of advice might have a conflicting (the same) level of precedence. Use @Order to explicitly state which advice should be applied first. Play around with the order by setting the order of your aspect to lower or higher, for instance by setting the value to LOWEST_PRECEDENCE or HIGHEST_PRECEDENCE:

@Order(Ordered.HIGHEST_PRECEDENCE)
@Aspect
public class YourAspect {
    ...
}
Michiel
  • 2,914
  • 1
  • 18
  • 27
  • Thanks for the response, but it does not seem to work: Ordered.HIGHEST_PRECEDENCE will causes http requests to fail - "java.lang.IllegalStateException: No MethodInvocation found..advices with order HIGHEST_PRECEDENCE will execute before ExposeInvocationInterceptor!". If I add @ Oder, Ordered.HIGHEST_PRECEDENCE+1 or any greater value like +2, 10 or Ordered.LOWEST_PRECEDENCE, LOWEST_PRECEDENCE - 1, 2, 10 all failed to solve the problem. In addition, logging of @ Retryable method is failing too..!, logging for @ Retryable works fine if @ Order is not present on the aspect class. – Pavan Kumar Oct 26 '19 at 03:58
  • Further, Adding @ Order on logAfterReturning() seems to have no effect at all! – Pavan Kumar Oct 26 '19 at 07:50