springboot事务的使用
时间: 2023-11-04 08:57:12 浏览: 92
在Spring Boot中,使用事务非常简单。首先需要在配置类上添加注解@EnableTransactionManagement来开启事务支持。然后,只需在访问数据库的Service方法上添加注解@Transactional即可实现事务的管理。如果使用了spring-boot-starter-jdbc依赖,框架会自动注入DataSourceTransactionManager实例,如果使用了spring-boot-starter-data-jpa依赖,框架会自动注入JpaTransactionManager实例。这样我们就可以在方法中使用@Transactional注解来进行事务的使用了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [SpringBoot 事务的使用](https://blog.csdn.net/qq_42402854/article/details/91411953)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *3* [SpringBoot事务详解](https://blog.csdn.net/lemon_TT/article/details/127089922)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文