这里介绍了 @Pointcut("this..") 和 @Pointcut("target()") 的区别: 在于拦截的方法是原对象还是代理对象
2-4对象匹配
匹配对象:

11111111111111111111111111111111
匹配对象11111
/**
* //匹配AOP对象的目标对象为指定类型的方法,即LogService的aop代理对象的方法
* @Pointcut("this(com.imooc.log.Loggable)")
* //匹配实现Loggable接口的目标对象(而不是aop代理后的对象)的方法
* @Pointcut("target(com.imooc.log.Loggable)")
* //this 可以拦截 DeclareParents(Introduction)
* //target 不拦截 DeclareParents(Introduction)
* //匹配所有以Service结尾的bean里头的方法
* @Pointcut("bean(*Service)")
* Created by cat on 2016-12-04.
*/
@Aspect
@Component
public class ObjectAspectConfig {
@Pointcut("bean(logService)")
public void matchCondition(){}
@Before("matchCondition()")
public void before(){
System.out.println("");
System.out.println("###before");
}
}
匹配对象:
1:this(包名):匹配AOP对象的目标对象指定类型的方法;
2:target(包名):匹配实现接口的目标对象的方法(不是AOP代理后的对象);
3:bean(包名):匹配所有以Service结尾的bean里头的方法;
匹配对象:
匹配对象示例
匹配对象 this target bean
匹配对象的方法
Pointcut匹配对象
@Pointcut("this()")——实现类,代理对象;
@Pointcut("target()")——所有实现他的类
@Pointcut("bean()")——过滤Spring托管的bean的实例,通过bean的名称进行过滤
匹配对象
//匹配AOP对象的目标对象为指定类型的方法,即DemoDao的aop代理对象的方法
@Pointcut("this(com.imooc.DemoDao)")
pblic void thisDemo(){}
//匹配实现IDao接口的目标对象(而不是aop代理后的对象)的方法,这里即DemoDao的方法
@Pointcut("target(com.imooc.IDao)")
public void targetDemo(){}
//匹配所有以Service结尾的bean里头的方法
@Pointcut("bean(*Service)")
public void beanDemo(){}
target匹配对象

target匹配对象
匹配对象 get
2-4匹配对象

Pointcut匹配对象
@Pointcut("this()"),实现类,代理对象;
@Pointcut("target()"),所有实现他的类
@Pointcut("bean()") 过滤spring托管的bean的实例,通过bean的名称进行过滤
this、target、bean匹配对象
匹配对象 @Pointcut(this),实现类,代理对象;
@Pointcut(target),所有实现他的类
Bean方法
this拦截Loggable接口实现的方法,这里和target一样
Introduction:动态生成方法
在没有Intro度餐厅时,this和target一样,有了以后this可以拦截这些生成的方法,target不能拦截
匹配对象
this
target
bean
匹配对象
target无法拦截introduction动态生成的方法
匹配对象