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