@Around is the most powerful advice type in Spring AOP. It wraps a method invocation, so your code runs before and after the target method, decides whether the target runs at all, and can change its arguments, return value or exceptions. Use it for cross-cutting concerns such as timing, caching, retries, transaction-like behaviour and security checks.
The advice receives a ProceedingJoinPoint. The target method only executes when you call proceed().
The other advice types (@Before, @AfterReturning, @AfterThrowing, @After) run at a fixed point and cannot control the call. @Around surrounds it. Its method must take a ProceedingJoinPoint as the first parameter and normally returns Object, which is the value the caller receives.
Every call to a method in com.example.service and its subpackages is timed. The finally block records the duration even when the method throws.
Spring AOP needs the starter, and in Spring Boot the proxying is auto-configured.
Without Spring Boot, add @EnableAspectJAutoProxy to a configuration class. The aspect must be a Spring bean, which is why @Component accompanies @Aspect.
| Capability | Example |
|---|---|
| Skip the target method | Return a cached value without calling proceed() |
| Change arguments | Call proceed(newArgs) with sanitised values |
| Change the result | Wrap or transform the returned object |
| Handle exceptions | Catch, retry or translate an exception |
| Call the target more than once | Retry logic |
A simple retry aspect shows several of these together.
This assumes a custom @Retry annotation with a times() attribute. The pointcut @annotation(retry) binds the annotation instance to the advice parameter.
execution(* com.example.service.*.*(..)) matches any method in a package.@annotation(com.example.Audited) matches methods carrying an annotation.within(com.example.web..*) matches types in a package.@within(org.springframework.stereotype.Service) matches classes with a stereotype.Define a named pointcut with @Pointcut and reuse it across advice so expressions stay in one place.
proceed(). The target silently never runs, which is correct only when intended.void-looking advice that returns null breaks callers that expect a value.final methods are not intercepted. For field access, constructors or non-Spring objects, use full AspectJ weaving.@Order.Prefer the least powerful advice type that solves the problem. Use @Before or @AfterReturning when you do not need to control the call, because @Around makes mistakes easier.
It is a join point that adds proceed() to the usual JoinPoint methods. Only @Around advice can use it.
For a method that returns a value, yes: return what proceed() returned, or a replacement. If the target returns void, the advice can return null.
Yes. Wrap proceed() in try/catch to handle, log, retry or translate the exception. Rethrow what you do not handle.
Not with Spring's proxy-based AOP. Make the method public on a Spring bean, or use AspectJ load-time or compile-time weaving.
@Around advice wraps a method call and gives you full control over it through ProceedingJoinPoint.proceed(). It suits timing, caching, retries and security, but proxy limits such as self-invocation apply. Call proceed() deliberately, return its result and choose a narrower advice type when you can.