Bird
0
0

How can you combine Spring AOP with custom annotations to apply advice only to methods marked with @TrackExecution?

hard📝 Application Q9 of 15
Spring Boot - Aspect-Oriented Programming
How can you combine Spring AOP with custom annotations to apply advice only to methods marked with @TrackExecution?
AUse XML configuration to bind advice to annotation
BDefine a pointcut using @annotation(TrackExecution) and apply advice there
CManually call advice methods inside annotated methods
DUse @Before advice on all methods and check annotation with reflection
Step-by-Step Solution
Solution:
  1. Step 1: Use annotation-based pointcut

    Spring AOP allows pointcuts to match methods with specific annotations using @annotation.
  2. Step 2: Apply advice to matched methods

    Advice runs only on methods annotated with @TrackExecution by defining pointcut accordingly.
  3. Final Answer:

    Define a pointcut using @annotation(TrackExecution) and apply advice there -> Option B
  4. Quick Check:

    Use @annotation pointcut for custom annotation advice [OK]
Quick Trick: Use @annotation in pointcut for custom annotation advice [OK]
Common Mistakes:
  • Checking annotation inside advice manually
  • Calling advice methods manually
  • Using XML config instead of annotations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes