Bird
0
0

You want to log method calls for all public methods in com.example.repository package and its subpackages before execution. Which @Before pointcut expression is correct?

hard📝 Application Q8 of 15
Spring Boot - Aspect-Oriented Programming
You want to log method calls for all public methods in com.example.repository package and its subpackages before execution. Which @Before pointcut expression is correct?
A@Before("execution(public * com.example.repository..*(..))")
B@Before("execution(* com.example.repository.*(..))")
C@Before("execution(public * com.example.repository.*.*(..))")
D@Before("execution(public * com.example.repository.*(..))")
Step-by-Step Solution
Solution:
  1. Step 1: Understand pointcut syntax for package and subpackages

    .. in package means all subpackages; * matches method names; public restricts visibility.
  2. Step 2: Compare options

    @Before("execution(public * com.example.repository..*(..))") correctly uses public, package with .. for subpackages, and method wildcard *(..).
  3. Final Answer:

    @Before("execution(public * com.example.repository..*(..))") -> Option A
  4. Quick Check:

    Use .. for subpackages and public for visibility [OK]
Quick Trick: Use '..' to include subpackages in pointcut [OK]
Common Mistakes:
  • Omitting '..' to include subpackages
  • Incorrect method wildcard usage
  • Missing public visibility in pointcut

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes