SpringAOP学习笔记
1、Spring AOP 中的 JoinPoint 只支持方法执行的JoinPoint
2、Spring AOP 中的 Pointcut
org.springframework.aop.Pointcut为Pointcut的最顶层抽象。
package org.springframework.aop;
public interface Pointcut {
ClassFilter getClassFilter();
MethodMatcher getMethodMatcher();
Pointcut TRUE = TruePointcut.INSTANCE;
}
getClassFilter和MethodMatcher分别用于匹配将被织入的操作对象以及相应的方法。
package org.springframework.aop;
public interface ClassFilter {
//如果clazz与我们关注的现象相符时返回true,负责返回false
boolean matches(Class<?> clazz);
//静态参数 如果类型对于我们要扑捉的Pointcut来说无所谓,我们可讲此参数传递给Pointcut
ClassFilter TRUE = TrueClassFilter.INSTANCE;
}
package org.springframework.aop;
public interface MethodMatcher {
boolean matches(Method method, Class<?> targetClass);
/**
* 是否对参数值敏感
* 如果为false表明匹配时不需要判断参数值(参数值不敏感),称之为StaticMethodMatcher,这时只有
* matches(Method method, Class<?> targetClass); 被执行,执行结果可以缓存已提高效率。
* 如果为true表明匹配时需要判断参数值(参数值敏感),称之为DynamicMethodMatcher,这时先执行
* matches(Method method, Class<?> targetClass);如果返回true,然后再执行
* boolean matches(Method method, Class<?> targetClass, Object[] args);已做进一步判断
*
*/
boolean isRuntime();
boolean matches(Method method, Class<?> targetClass, Object[] args);
MethodMatcher TRUE = TrueMethodMatcher.INSTANCE;
}