Bird
0
0

Given this Spring AOP advice snippet, what will be logged when processOrder() method completes successfully?

medium📝 Command Output Q13 of 15
Spring Boot - Aspect-Oriented Programming
Given this Spring AOP advice snippet, what will be logged when processOrder() method completes successfully?
@Before("execution(* com.example.service.*.*(..))")
public void logStart() {
    System.out.println("Method started");
}

@AfterReturning("execution(* com.example.service.*.*(..))")
public void logEnd() {
    System.out.println("Method completed");
}
AMethod started and Method completed
BMethod completed only
CMethod started only
DNo output logged
Step-by-Step Solution
Solution:
  1. Step 1: Analyze @Before advice

    Before processOrder() runs, "Method started" is printed.
  2. Step 2: Analyze @AfterReturning advice

    After successful completion, "Method completed" is printed.
  3. Final Answer:

    Method started and Method completed -> Option A
  4. Quick Check:

    Before + AfterReturning logs both messages [OK]
Quick Trick: Both @Before and @AfterReturning run on success [OK]
Common Mistakes:
  • Thinking only one advice runs
  • Confusing @AfterReturning with @AfterThrowing
  • Assuming no logs if method returns void

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes