After (finally) advice runs however a matched method execution exits. It is declared using @After 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.
BusinessAspect.java
package com.kruders.spring.aspect;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class BusinessAspect {
@Pointcut("execution(* com.kruders.spring.aop.BusinessImpl*.*(..))")
public void businessMethods() { }
@After("businessMethods()")
public void after() {
System.out.println("After method is called");
}
}
2. Output
When you run the above example you’ll get an output like:
Do Something Here
After method is called

No comments yet.