Joinpoint:在SpringAoP中,只支持Method Execution (方法执行)的Joinpoint,对于类型中的属性,我们可以通过对setter,getter方法的拦截从而达到相同的效果。
Pointcut: spring AoP以接口定义 aop.PointCut作为其AoP框架中说有 PointCut的最顶层抽象,该接口提供了两个方法用来帮助捕捉JoinPoint,并提供了一个TruePointcut类型实例。PointCut提供了三个方法:
public interface Pointcut { /** * Return the ClassFilter for this pointcut. * @return the ClassFilter (never <code>null</code>) */ ClassFilter getClassFilter(); /** * Return the MethodMatcher for this pointcut. * @return the MethodMatcher (never <code>null</code>) */ MethodMatcher getMethodMatcher(); /** * Canonical Pointcut instance that always matches. */ Pointcut TRUE = TruePointcut.INSTANCE; }
其中ClassFilter用于匹配将被织入操作的对象,MethodMatcher用于匹配将被织入操作的方法,ClassFilter中提供了两个方法:
public interface Pointcut { /** * Return the ClassFilter for this pointcut. * @return the ClassFilter (never <code>null</code>) */ ClassFilter getClassFilter(); /** * Return the MethodMatcher for this pointcut. * @return the MethodMatcher (never <code>null</code>) */ MethodMatcher getMethodMatcher(); /** * Canonical Pointcut instance that always matches. */ Pointcut TRUE = TruePointcut.INSTANCE; }
MethodMatcher则比较繁杂,提供了4个方法:
public interface Pointcut { /** * Return the ClassFilter for this pointcut. * @return the ClassFilter (never <code>null</code>) */ ClassFilter getClassFilter(); /** * Return the MethodMatcher for this pointcut. * @return the MethodMatcher (never <code>null</code>) */ MethodMatcher getMethodMatcher(); /** * Canonical Pointcut instance that always matches. */ Pointcut TRUE = TruePointcut.INSTANCE; }其中,当 isRuntime为false时,只执行两个参数的matches,忽略参数去进行匹配,这种类型的MethodMatcher称为StaticMethodMatcher,因为不用每次都去匹配结构,就可以在框架内部缓存以提高性能。当isRuntime为true时,表明会对方法调用的参数进行匹配检查,称之为DynamicMethodMatcher,由于无法进行缓存,所以效率较差。若第一个matches方法执行完返回false,这后面都将不会执行。
常见Pointcut:
NameMatchMethodPointcut:最简单的Pointcut实现,属于staticMethodMatcherPointcut的子类,可以根据自身指定的一组方法名称与Joinpoint处的方法的方法名称进行匹配,可以使用“*”进行简单的模糊匹配。JdkRegexpMethodPoint和Perl15RegexpMethodPoint属于StaticMethodMatcherPointcut的子类,专门提供基于正则表达式的实现分支,其中第一个的实现是基于JDK1.4之后引入的JDK标准正则表达式。第二种是基于Perl15风格的正则表达式。AnnontationMatchingPointcut:使用注解来匹配JoinPointComposablePointcut:实现Pointcut的逻辑运算功能ControlFlowPointcut:用于实现拦截被特定对象调用的joinpoint
转载于:https://www.cnblogs.com/Qbright/archive/2012/07/24/2606806.html
相关资源:DirectX修复工具V4.0增强版