Bird
0
0

You want to add logging before and after all methods in your service without changing each method. Which AOP approach best achieves this in Spring Boot?

hard📝 Application Q15 of 15
Spring Boot - Aspect-Oriented Programming
You want to add logging before and after all methods in your service without changing each method. Which AOP approach best achieves this in Spring Boot?
ACreate a new service class that duplicates all methods with logging
BManually add logging code inside every service method
CUse @Before and @After advices with a pointcut matching all service methods
DUse @Transactional annotation on service methods
Step-by-Step Solution
Solution:
  1. Step 1: Identify the goal

    You want to add logging around all service methods without modifying them individually.
  2. Step 2: Choose the correct AOP approach

    @Before and @After advices with a pointcut covering all service methods allow running code before and after each method automatically.
  3. Final Answer:

    Use @Before and @After advices with a pointcut matching all service methods -> Option C
  4. Quick Check:

    AOP advices automate cross-cutting tasks = C [OK]
Quick Trick: Use @Before and @After with pointcut for all methods [OK]
Common Mistakes:
  • Adding logging manually in every method
  • Duplicating service classes unnecessarily
  • Confusing logging with transaction management

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes