liveBook · Manning

Proceed() method

As explained in Spring Start Here, Second Edition

The proceed() method continues an intercepted invocation, optionally supplying replacement arguments.

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

How Spring Start Here, Second Edition covers it

How deep it goes
Explains delegation, argument substitution, return-value handling, and exception propagation, including what happens when delegation is skipped.
Examples
Demonstrates publishing a comment with replacement text, logging the method result, and returning FAILED to the caller.
What you can do after
Apply it in Spring AOP to call the intercepted method with original or replacement arguments, then pass through or replace its result.
How it connects
Connects Spring AOP with @Around advice and ProceedingJoinPoint.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.