import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class LoggingAspect {
@Before("execution(* com.example.MyClass.myMethod(..))")
public void logBeforeMethod() {
System.out.println("Logging before method execution...");
}
}
public class MyClass {
public void myMethod() {
System.out.println("My method is being executed...");
}
}
shell
ajc -cp aspectjrt.jar LoggingAspect.java
public class Main {
public static void main(String[] args) {
MyClass obj = new MyClass();
obj.myMethod();
}
}
Logging before method execution...
My method is being executed...