Bird
0
0

Why does this @Before advice not execute?

medium📝 Debug Q7 of 15
Spring Boot - Aspect-Oriented Programming
Why does this @Before advice not execute?
@Before("execution(* com.example.service.*.process(..))")
public void log() {
  System.out.println("Logging");
}

Given the target method is com.example.Service.process().
AAdvice method must return a value
BAdvice method is missing @Aspect annotation
CAdvice method must have parameters
DPointcut expression does not match the target class name
Step-by-Step Solution
Solution:
  1. Step 1: Analyze pointcut expression

    The pointcut targets classes in package com.example.service, but target class is com.example.Service (case sensitive).
  2. Step 2: Confirm other conditions

    @Aspect is needed on the aspect class, not the advice method; parameters and return type are optional for @Before.
  3. Final Answer:

    Pointcut expression does not match the target class name -> Option D
  4. Quick Check:

    Pointcut must match exact package and class names [OK]
Quick Trick: Pointcut must exactly match target method signature [OK]
Common Mistakes:
  • Ignoring case sensitivity in package/class names
  • Misplacing @Aspect annotation
  • Expecting advice methods to require parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes