引用
this - limits matching to join points (the execution of methods when using Spring AOP) where the bean
reference (Spring AOP proxy) is an instance of the given type
• target - limits matching to join points (the execution of methods when using Spring AOP) where the target
object (application object being proxied) is an instance of the given type
似乎看不出两者的具体区别,我试着做了一个测试:
切面定义类:
Java代码 收藏代码
package com.baobaotao.expression;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class PreGreetingAspect{
@Before("target(com.baobaotao.expression.NaiveWaiter)")
public void beforeGreeting(){
System.out.println("How are you");
}
}
目标类接口:
Java代码 收藏代码
package com.baobaotao.expression;
public interface Waiter {
public void greetTo(String name);
public void serveTo(String name);
}
目标接口实现类:
Java代码 收藏代码
package com.baobaotao.expression;
public class NaiveWaiter implements Waiter {
public void greetTo(String name) {
System.out.println("greet to "+name+"...");
}
public void serveTo(String name){
System.out.println("serving "+name+"...");
foo(name);
}
public void foo(String name){
System.out.println("foo "+name+"...");
}
}
然后是配置:
Java代码 收藏代码