Bird
0
0

What is wrong with the following @AfterReturning advice method?

medium📝 Debug Q6 of 15
Spring Boot - Aspect-Oriented Programming
What is wrong with the following @AfterReturning advice method?
@AfterReturning(pointcut = "execution(* service.*.fetchData(..))", returning = "result")
public void advice() {
    System.out.println("Result: " + result);
}
AThe @AfterReturning annotation cannot be used with void methods.
BThe pointcut expression syntax is incorrect.
CThe advice method should return a value.
DThe advice method lacks a parameter named 'result' to receive the returned value.
Step-by-Step Solution
Solution:
  1. Step 1: Check returning attribute usage

    The returning = "result" attribute indicates the advice method must have a parameter named result.
  2. Step 2: Verify method signature

    The advice method currently has no parameters, so it cannot access the returned value.
  3. Final Answer:

    The advice method lacks a parameter named 'result' to receive the returned value. correctly identifies the missing parameter as the error.
  4. Quick Check:

    Returning attribute requires matching method parameter [OK]
Quick Trick: Returning attribute requires matching method parameter [OK]
Common Mistakes:
  • Forgetting to add parameter matching the returning attribute
  • Assuming advice method must return a value
  • Miswriting pointcut expression syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes