In Spring AOP, proceed() lets an @Around advice continue an intercepted invocation. Calling it without arguments passes the original arguments; calling it with an object array supplies replacements. The method returns the intercepted method’s result, which the advice can pass through or replace before returning to the caller. section 6.2.2 section 6.2.1
Keep these effects in mind when using proceed():
- Without a call to proceed(), the intercepted method does not run; the advice runs in its place. section 6.2.1
- Because proceed() can throw Throwable from the intercepted method, the advice can propagate it or handle it with try-catch-finally. section 6.2.1
Listing 6.15 Altering the parameters and the returned value
@Aspect
public class LoggingAspect {
private final Logger logger =
Logger.getLogger(LoggingAspect.class.getName());
@Around("execution(* com.example.services.*.*(..))")
public Object log(ProceedingJoinPoint joinPoint) throws Throwable {
String methodName = joinPoint.getSignature().getName();
Object [] arguments = joinPoint.getArgs();
logger.info("Method " + methodName +
" with parameters " + Arrays.asList(arguments) +
" will execute");
Comment comment = new Comment();
comment.setText("Some other text!");
Object [] newArguments = {comment};
Object returnedByMethod = joinPoint.proceed(newArguments); #A
logger.info("Method executed and returned " + returnedByMethod);
return "FAILED"; #B
}
} This aspect passes replacement comment arguments to proceed(), observes the intercepted method’s result, then returns a different value to the caller. section 6.2.2
