cglib

参考:
https://www.runoob.com/w3cnote/cglibcode-generation-library-intro.html

spring 事务 EnableTransactionManagement 与 Transactional

基于 springboot 2.5.3

先说spring自动配置 SpringBootApplication 注解,加载配置

bean 的加载,spring.factory 文件:https://blog.csdn.net/qq_32370913/article/details/105924209 (【springboot】为何不使用@EnableTransactionManagement就能使用事务?)

  1. org.springframework.boot.autoconfigure.EnableAutoConfiguration
  2. org.springframework.boot.autoconfigure.AutoConfigurationImportSelector
  3. org.springframework.boot.autoconfigure.AutoConfigurationImportSelector#selectImports
  4. org.springframework.boot.autoconfigure.AutoConfigurationImportSelector#getAutoConfigurationEntry
  5. org.springframework.boot.autoconfigure.AutoConfigurationImportSelector#getCandidateConfigurations
  6. org.springframework.core.io.support.SpringFactoriesLoader#loadFactoryNames
  7. org.springframework.core.io.support.SpringFactoriesLoader#loadSpringFactories (这里加载 spring.factory 文件)

此步是说明项目不加 EnableTransactionManagement 也可以使用事务(当然对应的方法必须可以拿到事务,不管是直接获取,还是从其他方法继承,还是别的(就是一个事务的传播))

加与不加 EnableTransactionManagement 到底有没有区别?

spring.factory 文件与事务相关的

  1. org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
  2. org.springframework.boot.autoconfigure.r2dbc.R2dbcTransactionManagerAutoConfiguration,\
  3. org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\
  4. org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\
  5. org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\

事务逻辑

https://www.jianshu.com/p/f84d50ba6d10 (声明式事务源码分析之EnableTransactionManagement,执行逻辑)