Bird
0
0

Why might you prefer @After advice over @AfterReturning advice in some cases?

hard📝 Conceptual Q10 of 15
Spring Boot - Aspect-Oriented Programming
Why might you prefer @After advice over @AfterReturning advice in some cases?
ABecause @After runs only before the method starts.
BBecause @After runs regardless of method success or failure, useful for cleanup.
CBecause @AfterReturning runs even if method throws exceptions.
DBecause @AfterReturning advice cannot access return values.
Step-by-Step Solution
Solution:
  1. Step 1: Compare advice execution timing

    @After runs always after method finishes, whether it succeeded or failed.
  2. Step 2: Use case for cleanup

    This makes @After ideal for cleanup tasks that must run no matter what.
  3. Final Answer:

    Because @After runs regardless of method success or failure, useful for cleanup. -> Option B
  4. Quick Check:

    @After = always runs after method, good for cleanup [OK]
Quick Trick: Use @After for always-run cleanup after method [OK]
Common Mistakes:
  • Thinking @After runs before method
  • Confusing @AfterReturning with @After
  • Assuming @AfterReturning runs on exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes