In Spring AOP, the @Around advice is used to run cross-cutting logic such as logging, performance monitoring, caching and retries around a bean method. It receives a ProceedingJoinPoint, so it can run code before the method, call proceed() to execute it, and run more code after it, including changing the result or handling exceptions.
This article focuses on practical Spring Boot usage: setting up the dependency, targeting methods with pointcuts and custom annotations, and avoiding the common proxy pitfalls.
Add the AOP starter, which brings in Spring AOP and AspectJ's annotations:
With Spring Boot, auto-configuration enables proxy-based aspects, so you do not need @EnableAspectJAutoProxy. An aspect is a Spring bean annotated with @Aspect and @Component.
Three rules apply to every @Around method:
ProceedingJoinPoint.Object, and the returned value is what the caller gets.throws Throwable, because proceed() can throw any exception from the target.If you do not call proceed(), the target method is skipped.
An execution(...) expression targets methods by signature. For more explicit and refactor-safe targeting, define your own annotation and match it with @annotation.
Now only methods marked @Timed are measured. This is the same pattern Micrometer's @Timed and Spring's @Transactional follow.
| Use case | What the advice does |
|---|---|
| Logging | Records arguments, result and duration |
| Performance monitoring | Times the call and reports metrics |
| Caching | Returns a stored value and skips proceed() |
| Retry | Calls proceed() again after a transient failure |
| Authorisation | Throws or returns early when a check fails |
| Exception translation | Catches low-level exceptions and throws domain exceptions |
A small retry example shows how proceed() can be called more than once:
For production retries use Spring Retry or Resilience4j, which add back-off and metrics. The example only illustrates the mechanism.
final classes and methods cannot be proxied by CGLIB.proceed(), otherwise callers receive null.@Order.They solve similar problems at different layers. A filter or HandlerInterceptor works on HTTP requests, while @Around works on any Spring bean method call.
Yes. Use pjp.getArgs() for the values and pjp.getSignature() for the method details. You can also bind arguments directly with args(...) in the pointcut.
The usual causes are a missing spring-boot-starter-aop dependency, an aspect that is not a bean, a pointcut that does not match, or a self-invocation that bypasses the proxy.
Use @Around in Spring AOP when you must control the method call itself: timing, caching, retries, security checks and exception translation. Pair it with a custom annotation for precise targeting, always call proceed() and return its result unless you intend to short-circuit, and remember that only calls through the Spring proxy are intercepted.