AspectJ Example With Annotation
Main.java File
package com.tkhts;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect // This annotation define the aspect
public class Main {
@Pointcut("execution(* *.*(..))")
//define pointcut, first * mean any package,
//second * means any class, third * means any method
void mypointcut(){
}
@Before("mypointcut()")
//@Before run before every class method run
public void start(){
System.out.println("Start Call ");
}
@After("mypointcut()")
//@After run before every class method about to end
public void stop(){
System.out.println("Stop Call");
}
}
TestAspectJ.java File
package com.tkhts;
public class TestAspectJ {
public static void main(String[] args) {
System.out.println("inside Main ");
System.out.println("Main Going to End");
}
}
Output



