Bird
0
0

Given this aspect code snippet:

medium📝 component behavior Q4 of 15
Spring Boot - Aspect-Oriented Programming
Given this aspect code snippet:
@Aspect
@Component
public class LogAspect {
  @Before("execution(* com.example.service.*.*(..))")
  public void logBefore() {
    System.out.println("Before method call");
  }
}

What will be printed when someService.someMethod() is called?
AException thrown
BAfter method call
CNo output
DBefore method call
Step-by-Step Solution
Solution:
  1. Step 1: Identify advice type

    The @Before advice runs before the matched method executes.
  2. Step 2: Match pointcut expression

    The pointcut matches all methods in com.example.service package, so someMethod() matches.
  3. Final Answer:

    Before method call -> Option D
  4. Quick Check:

    @Before advice prints before method [OK]
Quick Trick: @Before advice prints before method execution [OK]
Common Mistakes:
  • Expecting output after method
  • Ignoring pointcut matching
  • Assuming exception thrown

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes