Bird
0
0

How would you write a pointcut expression to match all methods annotated with @Transactional in any class inside com.example and its subpackages?

hard📝 Application Q9 of 15
Spring Boot - Aspect-Oriented Programming
How would you write a pointcut expression to match all methods annotated with @Transactional in any class inside com.example and its subpackages?
A@annotation(org.springframework.transaction.annotation.Transactional) && within(com.example..*)
Bexecution(@Transactional * com.example..*.*(..))
C@within(org.springframework.transaction.annotation.Transactional) && within(com.example..*)
Dexecution(* com.example..*.*(@Transactional))
Step-by-Step Solution
Solution:
  1. Step 1: Use @annotation to match method-level annotations

    @annotation matches methods annotated with the specified annotation.
  2. Step 2: Restrict to package and subpackages

    within(com.example..*) limits matching to the package and its subpackages.
  3. Final Answer:

    @annotation(org.springframework.transaction.annotation.Transactional) && within(com.example..*) -> Option A
  4. Quick Check:

    Method annotation match with package limit = @annotation(org.springframework.transaction.annotation.Transactional) && within(com.example..*) [OK]
Quick Trick: Use @annotation for method annotations, within for package [OK]
Common Mistakes:
  • Using @within instead of @annotation for methods
  • Trying to put annotation inside execution() incorrectly
  • Omitting package restriction

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes