Bird
0
0

How can you exclude logging advice from applying to methods annotated with @NoLogging in com.example package?

hard📝 Application Q9 of 15
Spring Boot - Aspect-Oriented Programming
How can you exclude logging advice from applying to methods annotated with @NoLogging in com.example package?
A@Before("execution(* com.example..*(..)) && !@annotation(com.example.NoLogging)") public void log() { ... }
B@Before("execution(* com.example..*(..)) || @annotation(com.example.NoLogging)") public void log() { ... }
C@Before("execution(* com.example..*(..))") @Exclude("@annotation(com.example.NoLogging)") public void log() { ... }
D@Before("execution(* com.example..*(..))") public void log(@NoLogging Object obj) { ... }
Step-by-Step Solution
Solution:
  1. Step 1: Use pointcut expression to exclude annotation

    The expression uses !@annotation(...) to exclude methods with @NoLogging.
  2. Step 2: Check other options

    @Before("execution(* com.example..*(..)) || @annotation(com.example.NoLogging)") public void log() { ... } includes methods with the annotation, @Before("execution(* com.example..*(..))") @Exclude("@annotation(com.example.NoLogging)") public void log() { ... } uses invalid @Exclude, and @Before("execution(* com.example..*(..))") public void log(@NoLogging Object obj) { ... } incorrectly tries to inject annotation as parameter.
  3. Final Answer:

    Option A with negation of annotation in pointcut -> Option A
  4. Quick Check:

    Exclude with !@annotation in pointcut [OK]
Quick Trick: Use !@annotation to exclude methods with specific annotation [OK]
Common Mistakes:
  • Using || instead of && ! for exclusion
  • Trying to use non-existent @Exclude annotation
  • Injecting annotation as method parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes