The @Around advice in AOP wraps a method call so your code runs before and after the target method and decides whether the method runs at all. It is the most powerful advice type because it can change the arguments, replace the return value, catch or translate exceptions and skip the call. In Spring AOP and AspectJ it receives a ProceedingJoinPoint, and you must call proceed() for the original method to execute.
Because @Around can change behaviour completely, use it only when @Before, @AfterReturning or @AfterThrowing are not enough.
| Advice | Runs | Can change arguments | Can change result | Can stop the call |
|---|---|---|---|---|
@Before | Before the method | No (can only inspect) | No | Only by throwing an exception |
@AfterReturning | After a normal return | No | No (can only inspect) | No |
@AfterThrowing | After an exception | No | No | No |
@After | After, always (finally) | No | No | No |
@Around | Around the whole call | Yes | Yes | Yes |
@Around is the only advice that controls the invocation itself, so it is the right tool for timing, caching, retries, transactions and circuit breakers.
The advice method must return Object (or a compatible type), take a ProceedingJoinPoint as its first parameter and declare throws Throwable.
The pointcut matches every method in the com.example.service package and its sub-packages. The finally block makes sure the duration is logged even when the target method throws.
To enable aspects in Spring Boot, add the spring-boot-starter-aop dependency. Plain Spring needs @EnableAspectJAutoProxy on a configuration class.
proceed(Object[] args) lets you pass different arguments to the target method, and whatever the advice returns becomes the result seen by the caller.
Keep the number and types of the arguments the same, otherwise the call fails at runtime. The returned value must match the target method's return type. For a void method, return null. Returning null from advice around a method with a primitive return type causes an error.
If you never call proceed(), the target method does not run. This is how a simple cache or feature flag works.
You can also catch exceptions from proceed() to translate them, retry or return a fallback value. Rethrow anything you do not intend to swallow, because hiding exceptions makes failures hard to find.
Spring's own @Transactional, @Cacheable and @Retryable are implemented with around-style interceptors.
Spring AOP is proxy based, so advice applies only to calls that go through the proxy. A method that calls another method on this bypasses the aspect. It also applies only to Spring beans, and with the default proxy settings private and final methods cannot be advised. If you need to advise any object, use full AspectJ with compile-time or load-time weaving.
The target method is never executed, and the caller receives whatever your advice returns. This is intentional for caching but a common bug otherwise.
Technically yes, but it is easier to get wrong. Prefer the narrower advice when you only need to run code before or after.
Not with Spring AOP's proxies. Move the logic into a public method of another bean or use AspectJ weaving.
Use @Order on the aspect classes. A lower value runs first on the way in and last on the way out.
@Around advice surrounds a method call and is the only advice type that can change arguments, change the result, handle exceptions and decide whether the method runs. Take a ProceedingJoinPoint, call proceed() exactly when you want the original method to execute, and prefer simpler advice types when they are enough.