史上最简洁Spring AOP原理分析
2020-12-07 13:54:03 0 举报
史上最简洁Spring AOP原理分析
作者其他创作
大纲/内容
1.ClassFilter:这个类是否符合
TransactionAutoConfiguration
InvocationHandler
Spring AOP最重要的工作,就是要创建好 Advisor
史上最简洁Spring AOP原理分析
AdvisorBeanFactoryTransactionAttributeSourceAdvisor
MethodInterceptor1
DynamicAdvisedInterceptor
Advisor
构造Advisor
MethodInterceptor3
MethodInterceptor4
AdvisorTransactionAttributeSourceAdvisor
Spring Boot的做法通过AopAutoConfiguration
TransactionProxyFactoryBean
2.MethodMatcher:Method是否符合
tx:annotation-driven/>
AdvisorInstantiationModelAwarePointcutAdvisorImpl
AdvisorDefaultBeanFactoryPointcutAdvisor
AdviceAspectJAroundAdviceAspectJMethodBeforeAdviceAspectJAfterAdviceAspectJAfterReturningAdviceAspectJAfterThrowingAdvice
proxyTargetClass=false目标对象有接口
MethodInvocation
通用
JdkDynamicAopProxy
MethodInterceptor2
IntroductionAdvisor
专用
Spring XML配置做法通过<aop:aspectj-autoproxy/>
PointcutTransactionAttributeSourcePointcut
执行
创建Proxy
只需要判断Class是否Match
Pointcut决定是否对bean创建Proxy
Pointcut
2. 通过AdvisorAdapter向Advisor索要
构造MethodInvocation然后执行
AdvisorAspectJPointcutAdvisor
proxyTargetClass=true无论目标对象是否有接口
PointcutAspectJExpressionPointcut
就是可以对所有的class和method进行切面,AspectJ
Advice
ObjenesisCglibAopProxy
判断是否需要创建Proxy
AnnotationTransactionAttributeSource针对@Transactional
创建Proxy
proxyTargetClass=false目标对象没有接口
收集MethodInterceptor
PointcutAdvisor
递归执行MethodInterceptor.invoke(MethodInvocation)
AdviceTransactionInterceptor
1.Advice自己就是MethodInerceptor
0 条评论
下一页