AOP Practice with Aspectj

AOP Practice with Aspectj

a plugin in eclipse named ajdt
update URL: http://download.eclipse.org/tools/ajdt/36/update

create a new AspectJ project with name aopdemo

a very simple sample class HelloWorld.java:
package com.sillycat.aspectjdemo;

public class HelloWorld {

public static void main(String[] args){
new HelloWorld().sayHello();

}
public void sayHello(){
System.out.print("hello ");
}
}

One aspectj class, AspectHelloWorld.aj:
package com.sillycat.aspectjdemo;

public aspect AspectHelloWorld {
pointcut greeting():
call(void HelloWorld.sayHello());
after() returning: greeting() {
        System.out.println("world");
    }
}

Add the library, [Java Build Path] ----> [Libraries] -----> [Add Variable] ----> [Aspectjrt_lib]

Run as AspectJ/Java Application

references:

你可能感兴趣的:(java,eclipse,AOP)