0
0
Spring Bootframework~10 mins

Pointcut expressions in Spring Boot - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Pointcut expressions
Start: Define Pointcut Expression
Match Join Points in Code
Apply Advice at Matched Points
Execute Advice
Continue Program Execution
Pointcut expressions select specific points in the program (join points) where advice runs, guiding when extra code executes.
Execution Sample
Spring Boot
execution(* com.example.service.*.*(..))
This pointcut matches execution of any method in any class inside com.example.service package.
Execution Table
StepPointcut ExpressionJoin Point EvaluatedMatch ResultAdvice Action
1execution(* com.example.service.*.*(..))com.example.service.UserService.getUser()MatchAdvice runs before getUser()
2execution(* com.example.service.*.*(..))com.example.service.OrderService.placeOrder()MatchAdvice runs before placeOrder()
3execution(* com.example.service.*.*(..))com.example.repository.UserRepository.save()No MatchAdvice does not run
4execution(* com.example.service.*.*(..))com.example.controller.UserController.listUsers()No MatchAdvice does not run
5execution(* com.example.service.*.*(..))End of join pointsStopNo more advice applications
💡 All join points checked; advice applied only where pointcut matches methods in com.example.service package.
Variable Tracker
VariableStartAfter 1After 2After 3After 4Final
Join PointNoneUserService.getUser()OrderService.placeOrder()UserRepository.save()UserController.listUsers()Checked all
Match ResultNoneMatchMatchNo MatchNo MatchFinal results recorded
Advice AppliedNoneYesYesNoNoAdvice applied only on matches
Key Moments - 2 Insights
Why does advice run for UserService methods but not for UserRepository methods?
Because the pointcut expression matches only methods inside the com.example.service package, not com.example.repository, as shown in execution_table rows 1-3.
What happens if a method signature changes but stays in the same package?
The pointcut still matches because it uses wildcards (*) and (..), so any method name and parameters in the package are matched, as seen in rows 1 and 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, does advice run for UserController.listUsers()?
ANo, advice does not run
BYes, advice runs
COnly sometimes
DDepends on method parameters
💡 Hint
Check row 4 in the execution_table where UserController.listUsers() is evaluated.
At which step does the pointcut expression stop checking join points?
AStep 3
BStep 4
CStep 5
DStep 2
💡 Hint
Look at the exit_note and row 5 in the execution_table.
If the pointcut expression changed to include com.example.repository package, what would happen at step 3?
AError occurs
BMatch and advice runs
CNo match and no advice
DAdvice runs only sometimes
💡 Hint
Refer to variable_tracker and execution_table row 3 for current behavior and imagine the package inclusion.
Concept Snapshot
Pointcut expressions select where advice runs in Spring AOP.
Syntax example: execution(* package.Class.method(..))
Wildcards * and .. match any method or parameters.
Only matched join points trigger advice.
Used to modularize cross-cutting concerns like logging.
Full Transcript
Pointcut expressions in Spring Boot define which methods or join points advice should apply to. The expression uses patterns like execution(* com.example.service.*.*(..)) to match all methods in a package. During execution, each join point is checked against the pointcut. If it matches, advice runs before or after that method. If not, advice is skipped. This lets developers add behavior like logging or security checks only where needed. Wildcards help match many methods easily. Understanding which methods match helps avoid confusion about when advice runs.