AspectJ @AfterReturning

After returning advice runs when a matched method execution returns normally. It is declared using @AfterReturning annotation.

For sample code in details, refer the following link. Click Here

1. Aspect Class

Now write a Aspect which will profile our business method.

package com.kruders.spring.aspect;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
public class BusinessAspect {
    @Pointcut("execution(* com.kruders.spring.aop.BusinessImpl*.*(..))")
    public void businessMethods() { }
    public void afterReturning() {
        System.out.println("After returning method is called");

2. Output

When you run the above example you’ll get an output like:

Do Something Here
After returning method is called

No comments yet.

Leave a Reply