Bird
0
0

What is wrong with this aspect code?

medium📝 Debug Q6 of 15
Spring Boot - Aspect-Oriented Programming
What is wrong with this aspect code?
@Aspect
public class MyAspect {
  @Before("execution(* com.example.*.*(..))")
  public void advice() {
    System.out.println("Advice called");
  }
}
AMissing @Component annotation to register aspect as bean
BIncorrect pointcut expression syntax
CAdvice method must return a value
DAspect class must be abstract
Step-by-Step Solution
Solution:
  1. Step 1: Check aspect registration

    Aspect classes need to be Spring beans, usually annotated with @Component or registered manually.
  2. Step 2: Verify other parts

    Pointcut syntax is correct, advice methods can be void, and aspect classes do not need to be abstract.
  3. Final Answer:

    Missing @Component annotation to register aspect as bean -> Option A
  4. Quick Check:

    Aspect must be a Spring bean [OK]
Quick Trick: Add @Component to make aspect a Spring bean [OK]
Common Mistakes:
  • Forgetting @Component
  • Wrong pointcut syntax
  • Expecting advice to return value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes