Search code examples
javaaopaspectj

Pointcut for methods with at least one annotation with any type


I am trying to have the following logic;

  • Method within class x.b.Classy
  • Public method
  • It has at least one annotation of any type

I have been trying to use this but annotation with any type logic is failing, how do I represent class type with 100% wildcard?

@Pointcut("within(x.b.Classy) && execution(public * *(..)) && @annotation(*)")

Though getting the following;

java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'identifier'
within(x.b.Classy) && execution(public * *(..)) && @annotation(*)
                                                               ^

How do I represent any type of annotation within my pointcut definition?


Solution

  • I think that what you want is something like:

    @Pointcut("within(x.b.Classy) && execution(@(*) public * *(..))")