0

I am trying to capture my annotation in an AOP pointcut like this (as seen on this question):

@After("@annotation(com.mypackage.annotation.Traza)")
        protected void logAnnotatedMethods(JoinPoint pjp, Traza traza) throws Throwable {
            LOGGER.info("It's here");
            LOGGER.info("Traza:" + traza);
        }

But I keep getting a java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut exception. If I remove the Traza parameter then it works and the pointcut is working wherever I annotate it with @Traza.

I know I can use reflection to obtain the annotation but shouldn't this be working too?

Community
  • 1
  • 1
M Rajoy
  • 4,028
  • 14
  • 54
  • 111

1 Answers1

1

Anyone with the same problem, here's the solution:

@After("@annotation(traza)")
protected void logAnnotatedMethods(JoinPoint pjp, Traza traza) throws Throwable {
    LOGGER.info("It's here");
    LOGGER.info("Traza:" + traza);
}

That is, set the argument name to the @annotation bit in the @After annotation.

M Rajoy
  • 4,028
  • 14
  • 54
  • 111