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

No comments yet.