Bird
0
0

You want to log execution time of all service methods in com.example.service. Which advice type and pointcut combination is best?

hard📝 Application Q8 of 15
Spring Boot - Aspect-Oriented Programming
You want to log execution time of all service methods in com.example.service. Which advice type and pointcut combination is best?
A@AfterThrowing("execution(* com.example.service..*(..))") with timing logic
B@Around("execution(* com.example.service..*(..))") with timing logic
C@AfterReturning("execution(* com.example.service.*.*(..))") with timing logic
D@Before("execution(* com.example.service.*.*(..))") with timing logic
Step-by-Step Solution
Solution:
  1. Step 1: Identify advice for timing

    @Around advice can run code before and after method execution, ideal for timing.
  2. Step 2: Choose correct pointcut

    Use com.example.service..* to include all methods in package and subpackages.
  3. Final Answer:

    @Around("execution(* com.example.service..*(..))") with timing logic -> Option B
  4. Quick Check:

    @Around advice best for measuring execution time [OK]
Quick Trick: @Around advice wraps method for timing [OK]
Common Mistakes:
  • Using @Before or @AfterReturning for timing
  • Wrong pointcut missing subpackages
  • Using @AfterThrowing incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes