Bird
0
0

Consider the following Spring AOP aspect:

medium📝 Predict Output Q4 of 15
Spring Boot - Aspect-Oriented Programming
Consider the following Spring AOP aspect:
@Aspect
@Component
public class AuditAspect {
  @Before("execution(* com.example.service.OrderService.placeOrder(..))")
  public void audit() {
    System.out.println("Audit: Order placement started");
  }
}

@Service
public class OrderService {
  public void placeOrder() {
    System.out.println("Order placed");
  }
}

What will be printed when orderService.placeOrder() is called?
AAudit: Order placement started Order placed
BOrder placed Audit: Order placement started
CAudit: Order placement started
DOrder placed
Step-by-Step Solution
Solution:
  1. Step 1: Identify advice timing

    The @Before advice runs before the target method.
  2. Step 2: Analyze method calls

    When placeOrder() is called, first the advice prints the audit message, then the method prints "Order placed".
  3. Final Answer:

    Audit: Order placement started Order placed -> Option A
  4. Quick Check:

    @Before advice runs before target method [OK]
Quick Trick: Before advice prints before method body [OK]
Common Mistakes:
  • Assuming advice runs after method
  • Ignoring advice execution order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes