2 After returning advice:
After returning advice runs when a matched method execution returns normally. It
is declared using the @AfterReturning annotation:
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.AfterReturning;
@Aspect
public class AfterReturningExample {
@AfterReturning(pointcut="com.xyz.myapp.service()", returning="retVal")
public void logRequiredTask(Object retVal) {
// ...
}}
The name used in the returning attribute must correspond to the name of a parameter in the advice method. When a method execution returns, the return value will be passed to the advice method as the corresponding argument value. A returning clause also restricts matching to only those method executions that return a value of the specified type.