@EnableTransactionManagement原理
?* 1)、@EnableTransactionManagement
?* ?? ??? ??? ?利用TransactionManagementConfigurationSelector給容器中會(huì)導(dǎo)入組件
?* ?? ??? ??? ?導(dǎo)入兩個(gè)組件
?* ?? ??? ??? ?AutoProxyRegistrar
?* ?? ??? ??? ?ProxyTransactionManagementConfiguration
?* 2)、AutoProxyRegistrar:
?* ?? ??? ??? ?給容器中注冊(cè)一個(gè) InfrastructureAdvisorAutoProxyCreator 組件;
?* ?? ??? ??? ?InfrastructureAdvisorAutoProxyCreator:?
?* ?? ??? ??? ?利用后置處理器機(jī)制在對(duì)象創(chuàng)建以后,包裝對(duì)象,返回一個(gè)代理對(duì)象(增強(qiáng)器),代理對(duì)象執(zhí)行方法利用攔截器鏈進(jìn)行調(diào)用;
?*?
?* 3)、ProxyTransactionManagementConfiguration 做了什么?
?* ?? ??? ??? ?1、給容器中注冊(cè)事務(wù)增強(qiáng)器;
?* ?? ??? ??? ??? ?1)、事務(wù)增強(qiáng)器要用事務(wù)注解的信息,AnnotationTransactionAttributeSource解析事務(wù)注解
?* ?? ??? ??? ??? ?2)、事務(wù)攔截器:
?* ?? ??? ??? ??? ??? ?TransactionInterceptor;保存了事務(wù)屬性信息,事務(wù)管理器;
?* ?? ??? ??? ??? ??? ?他是一個(gè) MethodInterceptor;
?* ?? ??? ??? ??? ??? ?在目標(biāo)方法執(zhí)行的時(shí)候;
?* ?? ??? ??? ??? ??? ??? ?執(zhí)行攔截器鏈;
?* ?? ??? ??? ??? ??? ??? ?事務(wù)攔截器:
?* ?? ??? ??? ??? ??? ??? ??? ?1)、先獲取事務(wù)相關(guān)的屬性
?* ?? ??? ??? ??? ??? ??? ??? ?2)、再獲取PlatformTransactionManager,如果事先沒有添加指定任何transactionmanger
?* ?? ??? ??? ??? ??? ??? ??? ??? ?最終會(huì)從容器中按照類型獲取一個(gè)PlatformTransactionManager;
?* ?? ??? ??? ??? ??? ??? ??? ?3)、執(zhí)行目標(biāo)方法
?* ?? ??? ??? ??? ??? ??? ??? ??? ?如果異常,獲取到事務(wù)管理器,利用事務(wù)管理回滾操作;
?* ?? ??? ??? ??? ??? ??? ??? ??? ?如果正常,利用事務(wù)管理器,提交事務(wù)
?* ?? ??? ??? ?
?*/
總結(jié)
以上是生活随笔為你收集整理的@EnableTransactionManagement原理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AOP原理解读
- 下一篇: Spring容器创建过程