A pointcut expression defines where advice should be applied by matching method executions or join points in the code.
Click to reveal answer
beginner
Explain the use of the execution() designator in pointcut expressions.
The execution() designator matches method executions based on method signature patterns like return type, method name, and parameters.
Click to reveal answer
intermediate
What does the pointcut expression execution(* com.example.service.*.*(..)) mean?
It matches the execution of any method with any return type, in any class inside the <code>com.example.service</code> package, with any number of arguments.
Click to reveal answer
intermediate
How can you combine multiple pointcut expressions?
You can combine pointcuts using logical operators like && (and), || (or), and ! (not) to create complex matching rules.
Click to reveal answer
beginner
What is the role of wildcards (*) and double dots (..) in pointcut expressions?
The wildcard * matches any single part like a method name or type, while .. matches any number of parameters or sub-packages.
Click to reveal answer
Which pointcut designator matches method executions by signature?
Athis()
Bwithin()
Cexecution()
Dargs()
✗ Incorrect
The execution() designator matches method executions based on method signatures.
What does the wildcard * represent in a pointcut expression?
ANo match
BAny number of parameters
CAny sub-package
DAny single part like a method name or type
✗ Incorrect
The * wildcard matches any single part such as a method name or type.
How do you exclude a pointcut from another using logical operators?
A!
B||
C&&
D==
✗ Incorrect
The ! operator negates a pointcut, effectively excluding it.
Which expression matches all methods in a package and its sub-packages?
Aexecution(* com.example..*.*(..))
Bexecution(* com.example.*.*(..))
Cwithin(com.example.*)
Dargs(com.example..*)
✗ Incorrect
The double dot .. matches sub-packages, so com.example..* includes all sub-packages.
What does execution(public * *(..)) match?
AAny method with no parameters
BAny public method with any return type and any parameters
COnly private methods
DOnly methods returning void
✗ Incorrect
It matches any public method regardless of return type or parameters.
Describe how pointcut expressions help in applying advice in Spring AOP.
Think about how you tell Spring where to run extra code.
You got /3 concepts.
Explain the difference between the wildcards * and .. in pointcut expressions.
One is for single parts, the other for multiple parts.
You got /2 concepts.
Practice
(1/5)
1. What does a pointcut expression in Spring Boot primarily do?
easy
A. Create new methods dynamically at runtime
B. Define the database connection settings
C. Select methods where extra code (advice) should run
D. Replace existing methods with new implementations
Solution
Step 1: Understand the purpose of pointcut expressions
Pointcut expressions specify where additional code, called advice, should be applied in existing methods without changing those methods.
Step 2: Differentiate from other concepts
They do not create or replace methods, nor configure databases. Their role is to select join points (methods) for advice.
Final Answer:
Select methods where extra code (advice) should run -> Option C
Quick Check:
Pointcut expression = Select methods for advice [OK]
Hint: Pointcuts pick methods to add code without changing them [OK]
Common Mistakes:
Confusing pointcuts with method creation
Thinking pointcuts configure databases
Believing pointcuts replace method code
2. Which of the following is the correct syntax to match all methods in package com.example.service using a pointcut expression?
easy
A. execution(* com.example.service..*(..))
B. execution(com.example.service.*.*(..))
C. execution(* com.example.service.*(..))
D. execution(* com.example.service.*.*(..))
Solution
Step 1: Understand the execution syntax
The syntax execution(* com.example.service.*.*(..)) matches any return type, any class in the package com.example.service, and any method with any parameters.
Step 2: Analyze other options
execution(com.example.service.*.*(..)) misses the wildcard for return type. execution(* com.example.service..*(..)) uses double dot .. which matches subpackages, not just the package. execution(* com.example.service.*(..)) misses the class wildcard.
Final Answer:
execution(* com.example.service.*.*(..)) -> Option D
Quick Check:
Use * for any class and method in package [OK]
Hint: Use * for any class and method in a package [OK]
Common Mistakes:
Omitting the return type wildcard *
Using .. instead of * for classes
Missing method wildcard *
3. Given the pointcut expression execution(public * com.example.repo.*Repository.find*(..)), which methods will it match?
medium
A. All methods named 'find' in any class in com.example.repo
B. All public methods starting with 'find' in any class ending with 'Repository' in package com.example.repo
C. All public methods in any class in com.example.repo
D. Only methods named exactly 'find' in any class ending with 'Repository'
Solution
Step 1: Break down the expression
public * means any public return type, com.example.repo.*Repository matches classes ending with 'Repository' in the package, and find*(..) matches methods starting with 'find' with any parameters.
Step 2: Match options to expression meaning
All public methods starting with 'find' in any class ending with 'Repository' in package com.example.repo correctly describes all public methods starting with 'find' in classes ending with 'Repository' in the package. Others are either too broad or too narrow.
Final Answer:
All public methods starting with 'find' in any class ending with 'Repository' in package com.example.repo -> Option B
Quick Check:
execution(public * com.example.repo.*Repository.find*(..)) = All public methods starting with 'find' in any class ending with 'Repository' in package com.example.repo [OK]
Hint: Look for wildcards * and method name patterns carefully [OK]
Common Mistakes:
Ignoring method name prefix 'find*'
Confusing class name pattern *Repository
Missing public modifier effect
4. Identify the error in this pointcut expression: execution(* com.example..service.*(..)
medium
A. Missing closing parenthesis at the end
B. Incorrect use of double dots '..' in package name
C. Wildcard '*' cannot be used for method names
D. Return type '*' is invalid
Solution
Step 1: Check syntax completeness
The expression is missing a closing parenthesis ')' at the end, which is required to close the execution() expression.
Step 2: Validate other parts
Double dots '..' are valid to match subpackages, '*' is valid for method names, and '*' is valid for return type.
Final Answer:
Missing closing parenthesis at the end -> Option A
Quick Check:
Check parentheses balance in execution() [OK]
Hint: Count parentheses carefully in pointcut expressions [OK]
Common Mistakes:
Forgetting closing parenthesis
Misunderstanding '..' usage
Thinking '*' is invalid for methods or return types
5. You want to create a pointcut expression that matches all methods in any class within com.app.service and its subpackages, but only methods that have exactly two parameters of any type. Which expression is correct?
hard
A. execution(* com.app.service..*.*(*, *))
B. execution(* com.app.service.*.*(..))
C. execution(* com.app.service..*.*(.., ..))
D. execution(* com.app.service..*.*(*))
Solution
Step 1: Understand package and subpackage matching
com.app.service..* matches classes in the package and all subpackages.
Step 2: Match method parameters exactly
(* , *) means exactly two parameters of any type. (..) means any number of parameters, so it's incorrect here.
Step 3: Analyze options
execution(* com.app.service..*.*(*, *)) correctly matches all classes in package and subpackages with exactly two parameters. Others either match any number of parameters or wrong parameter counts.
Final Answer:
execution(* com.app.service..*.*(*, *)) -> Option A
Quick Check:
Use (*, *) for exactly two parameters [OK]
Hint: Use (*, *) to match exactly two parameters [OK]
Common Mistakes:
Using (..) to match exact parameter count
Confusing single * with .. for subpackages
Missing commas between parameters
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.