spring 学习笔记------PointCut接口

学习spring 里的PointCut Interface接口
[b]1.什么是切入点:[/b]
概念:一个切入点是用来定义某一个通知该何时执行的一组联结点。再者什么是联结点呢,联结点就是程序执行过程中的一个特定点。
[b]2.spring 里的切入点的接口:[/b]

 public interface PointCut{

ClassFilter getClassFilter();

MethodMatcher getMethodMatcher();

}


这个getClassFilter()方法顾名思意是用来取得类过滤器的,getMethodMatcher()这个方法是用来的取得方法匹配器的。spring里提供了一些实现的切入点。
3.ClassFilter接口:
public interface ClassFilter {

boolean matches(Class clazz);

}
该接口只定义了一个方法,其参数class代表被检测类的实例,如何切入点适用于该类那么match()方法返回true;否侧返回false;

[b]4.MethodMatcher:接口[/b]

public interface MethodMatcher {

boolean matches(Method method, Class targetClass);

boolean isRuntime();

boolean matches(Method method, Class targetClass, Object[] args);

MethodMatcher TRUE = TrueMethodMatcher.INSTANCE;

}

spring 支持两种不同的MethodMatcher,静态的和动态的,一个MethodMatcher是哪一种取决于isRuntime()方法返回值,在使用MethodMatcher之前,spring会调用isRuntime()方法,如果返回false,那么就是静态的MethodMatcher,如果返回true。那么就是动态的。如果切入点是静态的,那么spring会对目标类的每一个方法调用一次matchesmethod,class);其返回值将被缓冲起来方便日后调用该方法时适用,这样,对每个方法的适用性的测试只会进行一次。之后调用该方法是将不再调用matches();如果切入点是动态的,那么spring仍然会在目标方法第一次调用时用matches(Method methhod,Class class);进行一个静态的测试来检查其总的适用性。不过,如果该测试返回true,那么在次基础上,每次该方法调用时 spring 会再次调用matcher(Method ,Class , Object[]);方法,这样,一个动态的MethodMatcher可以根据一次具体的方法调用,而不仅仅是方法本身,来决定切入点是否适用。显然,静态切入点的性能比动态切入点的性能要好的多,所以建议尽量用静态切入点。
5.已经实现的PointCut
	a.ComposablePointcut
b.ControlFlowPointcut
c.DynamicMethodMatcherPointcut
d.JdkRegexpMethodPointcut
e.NameMatchMethodPointcut
f.Perl5RegexpMethodPointcut
g.StaticMethodMatcherPointcut
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值