0
0
Spring Bootframework~10 mins

@Around advice for full control in Spring Boot - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - @Around advice for full control
Method call intercepted
@Around advice starts
Pre-processing logic
Proceed with original method?
NoSkip method execution
Yes
Call original method
Post-processing logic
Return result or modify
Method call completes
The @Around advice intercepts a method call, runs code before and after the method, and can decide to run or skip the original method, controlling the final result.
Execution Sample
Spring Boot
@Around("execution(* com.example.service.*.*(..))")
public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {
  System.out.println("Before method");
  Object result = pjp.proceed();
  System.out.println("After method");
  return result;
}
This advice prints messages before and after the original method runs, then returns the method's result.
Execution Table
StepActionEvaluationResult
1Method call interceptedMethod in target package calledProceed to advice
2Print 'Before method'Runs before original methodMessage shown
3Call pjp.proceed()Original method executesOriginal method result obtained
4Print 'After method'Runs after original methodMessage shown
5Return resultReturn value from adviceOriginal method result returned
6Method call completesCaller receives resultExecution ends
💡 Method call completes after advice returns the original method's result
Variable Tracker
VariableStartAfter Step 3Final
resultnulloriginal method's return valueoriginal method's return value
Key Moments - 3 Insights
Why do we call pjp.proceed() inside @Around advice?
Calling pjp.proceed() runs the original method. Without it, the original method is skipped (see execution_table step 3).
Can @Around advice modify the method's return value?
Yes, by changing the 'result' variable before returning it (see execution_table step 5).
What happens if pjp.proceed() is not called?
The original method does not run, and the advice can return a custom value or skip execution (not shown in this example but implied).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what happens at step 3?
AThe method call is intercepted
BThe advice prints 'After method'
CThe original method is executed
DThe advice returns the result
💡 Hint
Check the 'Action' and 'Result' columns at step 3 in the execution_table
At which step does the advice print 'Before method'?
AStep 2
BStep 4
CStep 1
DStep 5
💡 Hint
Look for the print action before the original method call in the execution_table
If pjp.proceed() is not called, what changes in the execution flow?
AThe advice prints 'After method' twice
BThe original method is skipped
CThe method call is never intercepted
DThe advice cannot return a result
💡 Hint
Refer to the key_moments section about skipping the original method
Concept Snapshot
@Around advice intercepts method calls
Runs code before and after method
Calls pjp.proceed() to run original method
Can skip or modify method execution
Returns final result to caller
Full Transcript
The @Around advice in Spring Boot intercepts method calls matching a pointcut. When a method is called, the advice runs first, allowing code before the method. Calling pjp.proceed() runs the original method and captures its result. After that, the advice can run more code and modify or return the result. If pjp.proceed() is not called, the original method is skipped. This gives full control over method execution flow.