Reputation: 1
I want to run an aspect using ElementType.PARAMETER
annotation but it does not work. The @Around tokenize
method is never called.
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface Tokenize {}
@Aspect
@Component
public class TokenizeAspect {
@Around("@annotation(Tokenize)")
public Object tokenize(ProceedingJoinPoint joinPoint) throws Throwable {
Object parameter = joinPoint.getArgs()[0];
return joinPoint.proceed();
}
}
public void addClientBankAccount(@Tokenize ClientBankAccountRequestCollection) {}
Upvotes: 0
Views: 393
Reputation: 67297
The Spring manual explains:
@annotation
: Limits matching to join points where the subject of the join point (the method being run in Spring AOP) has the given annotation.
You are not targetting an annotated method but an annotated parameter. That must be done differently (be careful with the parentheses):
execution(* *(.., @org.acme.Tokenize (*), ..))
This will match any method with any argument annotated by @Tokenize
. If additionally, you also need to fetch the actual annotation from the method argument and evaluate annotation parameters, check out my related answers here:
Upvotes: 2