spring AOP
2023-08-18 12:58:45 5 举报
AOP
作者其他创作
大纲/内容
TargetSource
- target:Object
+ TargetSource(Object target)+ getTargetClass():Class<?>[]
Pointcut
getClassFilter():ClassFiltergetMethodMatcher():MethodMatcher
BeforeAdvice
MethodBeforeAdvice
Cglib2AopProxy
- advised:AdvisedSupport
+ Cglib2AopProxy(AdvisedSupport advised)+ getProxy:Object+ intercept:Object
该类属于 Spring 自己的,无需用户实现。他为了让 Spring 的 Bean 生成过程中,能感知到用户的哪些 Bean 需要代理,而提供的这样一个组件,如果需要代理,则按用户规则生成代理类
切面定义
MethodBeforeAdviceInterceptor
- advice:MethodBeforeAdvice
+MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice)+ invoke(MethodInvocation methodInvocation):Object
BeanPostProcessor
AdvisedSupport
- targetSource:TargetSource- methodInterceptor:MethodInterceptor(aopalliance包的)- methodMatcher:MethodMatcher
+ set/get
关联
实现切面通知的Before
Advice(aopalliance包下的)
InvocationHandler(为JDK反射自带)
ProxyFactory
- advisedSupport:AdvisedSupport
+ProxyFactory(AdvisedSupport advisedSupport)+ getProxy():Object- createAopProxy():AopProxy
ClassFilter
matches(Class<?> clazz):Boolean
PointcutAdvisor
+ getPointcut():Pointcut
MethodInterceptor(为JDK反射自带)
用于生成代理类,在createAopProxy的时候决定使用JDK还是CGLIB来生成代理对象
切点表达式:判断我们的切点表达式,匹配的是否是这个类或这个类的这个方法。
BeanFactoryAware
setBeanFactory(BeanFactory beanFactory)
实现最终代理,可以通过JDK,也可以通过CGLIB
InstantiationAwareBeanPostProcessor
依赖做为返回值
实现接口
AopProxy
+ getProxy():Object
DefaultAdvisorAutoProxyCreator
- beanFactory:DefaultListableBeanFactory
AspectJExpressionPointcutAdvisor
- pointcut:AspectJExpressionPointcut- advice:Advice- expression:String
+ setExpression(String expression):void+ getPointcut():Pointcut+ getAdvice():Advice+ setAdvice(Advice advice):void
MethodMatcher
为了方便和Spring结合,提供一个类让用户使用
JdkDynamicAopProxy
+ JdkDynamicAopProxy((AdvisedSupport advised)+ getProxy():Object+ invoke():Object
AspectJExpressionPointcut
- pointcutExpression:PointcutExpression- SUPPORTED_PRIMITIVES:Set<PointcutPrimitive>
Advisor
+ getAdvice():Advice
0 条评论
下一页