0

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) {} 
1
  • 1
    Feedback, please. I don't find it particularly polite to first create a new account here for asking this question and then not reacting to answers. Commented Mar 18, 2022 at 15:42

1 Answer 1

3

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:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.