The @Around annotation in Spring AOP marks around advice, the most powerful advice type. It wraps a method call, so your code runs before and after the target, decides whether the target runs at all, and can change the arguments, the result or the exception.
Because it controls execution, @Around is the right tool for timing, caching, retries and transactions. This article shows the syntax, the role of ProceedingJoinPoint, and the mistakes to avoid.
Around advice is a method in an @Aspect class that receives a ProceedingJoinPoint as its first parameter. Spring calls your advice instead of the target method. Inside, you call proceed() to run the target (or the next advice in the chain), then continue with your own code.
The method must return Object and normally returns what proceed() returned. Whatever you return becomes the result seen by the caller.
The execution expression matches every method of every class in the service package. The method declares throws Throwable because proceed() can throw anything the target throws, and the finally block makes sure the measurement is logged even on failure.
| Capability | How |
|---|---|
| Run code before and after | Statements around pjp.proceed() |
| Skip the target method | Return without calling proceed() |
| Change the arguments | pjp.proceed(newArgs) with an Object[] |
| Change the return value | Return a different object |
| Handle or translate exceptions | Wrap proceed() in try and catch |
| Call the target more than once | Call proceed() in a loop (retry) |
The array you pass to proceed(Object[]) must have the same length and compatible types as the original arguments.
For production retry logic, prefer the Spring Retry library or resilience libraries, which add back-off and metrics.
proceed(). The target never runs and callers get null, usually by accident.void. A void around advice makes every advised method return null, and fails for methods that return a primitive.Throwable and do not rethrow, callers will not see the failure and transactions may not roll back.Throwable too broadly, which hides errors such as OutOfMemoryError.this bypass the proxy, so no advice runs.Use @Before, @AfterReturning or @AfterThrowing when you only need to observe a call. They cannot forget proceed() and are easier to read. Choose @Around when you need to control execution, for example to time a call, cache a result, retry, or open and close a resource around it.
It represents the intercepted method call. proceed() invokes the target, getArgs() returns the arguments, and getSignature() describes the method.
Yes. The value you return from the advice replaces what the caller receives, as long as its type is compatible with the target's return type.
The difference is negligible. All advice runs through the same proxy mechanism, and the cost is far lower than typical I/O.
Not with Spring AOP. It proxies calls to public methods on Spring beans. Use full AspectJ weaving for other cases.
@Around gives you complete control over a method call through ProceedingJoinPoint. Always return the result of proceed() unless you intend to replace it, rethrow exceptions you do not handle, and use simpler advice types when you only need to observe.