SpringBoot 自動開啓事務原理

1,TransactionAutoConfiguration

①,這是SpringBoot 的事務註解自動配置類,位於spring-boot-autoconfigure jar下。spring

②,@ConditionalOnClass(PlatformTransactionManager.class) 經過這一行,咱們知道只有在類路徑下有這個類存在時,事務自動配置類才生效mybatis

③,PlatformTransactionManager 位於spring-tx jar下spring-boot

2,spring-boot-starter-jdbc.jar 的依賴 

3,spring-boot-starter-data-jpa 

①,spring-boot-starter-data-jpa 依賴於spring-boot-starter-jdbcspa

4,mybatis-spring-boot-starter

①,mybatis-spring-boot-starter 依賴於spring-boot-starter-jdbcorm

5,總結

①,由於,jdbc,jpa,mybatis 的starter 都會依賴到 spring-tx.jar 因此事務註解會生效。事務

②,若有不對,還請你們指出it

相關文章
相關標籤/搜索