首页 > 其他分享 >SpringBoot项目为什么不需要添加@EnableTransactionManagement了

SpringBoot项目为什么不需要添加@EnableTransactionManagement了

时间:2022-09-26 23:13:49浏览次数:51  
标签:装配 SpringBoot spring 添加 EnableTransactionManagement 加载

SpringBoot项目为什么不需要添加@EnableTransactionManagement了

1、前言

我在刚开始搭建springBoot项目的时候,看见其他人在启动类上面使用了@EnableTransactionManagement注解,说是启动事务管理,类似于xml配置方式的 <tx:annotation-driven />。我并没有过多的研究,就只是跟着添加了注解。但是,后来发现,其实不需要添加也能够使用事务。

2、正文

1、首先看到SpringBoot的自动装配加载文件spring.factories,在其中搜索 transaction相关内容。

找到TransactionAutoConfiguration这个类,进去。

很明显可以看出是事务加载相关的内容,再往下翻。

就会看到通过两种动态代理JDK以及Cglib,Spring已经帮我们自动装配,无需手动引入@EnableTransactionManagement。大家明白了吗,可以多看下spring.factories文件,这里面加载了SpringBoot启动的所有有关自动装配类。

标签:装配,SpringBoot,spring,添加,EnableTransactionManagement,加载
From: https://www.cnblogs.com/dajiangyang/p/16732890.html

相关文章