安装好aspectj的和环境后,编写HelloWorld:
/**
* HelloWorld.java
*/
public class HelloWorld {
private void sayHello() {
System.out.println("hello world");
}
public static void main(String[] args) {
System.out.println("main start...");
HelloWorld hello = new HelloWorld();
hello.sayHello();
System.out.println("main end...");
}
}
/**
* HelloAspect.aj
*/
public aspect HelloAspect {
void around() : call(void sayHello()) {
System.out.println("before sayHello");
proceed();
System.out.println("after sayHello");
}
}