SpringBoot 自动开启事务原理

1,TransactionAutoConfiguration

①,这是SpringBoot 的事务注解自动配置类,位于spring-boot-autoconfigure jar下。

②,@ConditionalOnClass(PlatformTransactionManager.class) 通过这一行,我们知道只有在类路径下有这个类存在时,事务自动配置类才生效

③,PlatformTransactionManager 位于spring-tx jar下

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

3,spring-boot-starter-data-jpa 

①,spring-boot-starter-data-jpa 依赖于spring-boot-starter-jdbc

4,mybatis-spring-boot-starter

①,mybatis-spring-boot-starter 依赖于spring-boot-starter-jdbc

5,总结

①,因为,jdbc,jpa,mybatis 的starter 都会依赖到 spring-tx.jar 所以事务注解会生效。

扫描二维码关注公众号,回复: 1105785 查看本文章

②,如有不对,还请大家指出

猜你喜欢

转载自my.oschina.net/u/3574106/blog/1819352
今日推荐