Bird
0
0

You want to apply logging before and after all service methods in your Spring Boot app. Which combination of advice types should you use?

hard📝 Application Q8 of 15
Spring Boot - Aspect-Oriented Programming
You want to apply logging before and after all service methods in your Spring Boot app. Which combination of advice types should you use?
A@Before and @After
B@Around only
C@AfterReturning only
D@AfterThrowing only
Step-by-Step Solution
Solution:
  1. Step 1: Understand advice types

    @Before runs before method, @After runs after method, so together they cover both sides.
  2. Step 2: Evaluate other options

    @Around can do both but is more complex; @AfterReturning and @AfterThrowing cover only success or exception cases.
  3. Final Answer:

    @Before and @After -> Option A
  4. Quick Check:

    Use @Before and @After for before/after logging [OK]
Quick Trick: Combine @Before and @After for simple before/after logic [OK]
Common Mistakes:
  • Using only @AfterReturning or @AfterThrowing for all cases
  • Overcomplicating with only @Around advice

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes