当前位置:首页 > 后端开发 > springboot 开启事务以及手动提交事务

springboot 开启事务以及手动提交事务

6个月前 (05-26)60

springboot 开启事务以及手动提交事务

需要在服务类上加上两个注解

@Autowired
DataSourceTransactionManager dataSourceTransactionManager;
@Autowired
TransactionDefinition transactionDefinition;

手动开启事务

TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);

手动提交事务

dataSourceTransactionManager.commit(transactionStatus);//提交

手动回滚事务

dataSourceTransactionManager.rollback(transactionStatus);//最好是放在catch 里面,防止程序异常而事务一直卡在哪里未提交

作者:Java攻城狮 
来源链接:https://blog.csdn.net/whk_15502266662/article/details/107813885

“springboot 开启事务以及手动提交事务” 的相关文章

SpringBoot事务回滚@Transaction注解

SpringBoot事务回滚@Transaction 需要注意的几个事项: 1.注解@Transactional配置的...

SpringBoot 如何 进行 数据库事务管理

说起事务管理,首先我们要明确事务的概念,了解我们为什么要进行事务管理。 事务管理是对于一系列数据库操作进行管理,一个事务包含一个或多...

springBoot中声明式事务的使用

很多业务会牵连多张表的操作,有的时候一张表操作成功了,但是在中途保不齐出现什么幺蛾子,导致其他关联表操作失败,此时,事务就很重要了,保证了数据的准确...

Springboot JDBC的事务

SpringBoot 声明式事务管理, 提供两个注解: @EnableTransactionManagement: 表示是否开启事务管理,( 默认开启事务管理, 不加)...

Springboot事务使用与回滚

Springboot事务使用与回滚

Springboot中事务的使用: 1、启动类加上@EnableTransactionManagement注解,开启事务支持(其实默认是开启的)。 2、在使用事务...

springboot 手动回滚事务

关于springboot手动回滚事务有这样一个应用场景: SpringBoot事务注解@Transactional 事物回滚、手动回滚事物 上面一篇文章是介绍了利...

SpringBoot配置类替代@Transactional注解实现事务的控制

package com.example.zcw.config; import org.aspectj.lang.annotation.Aspect...

基于注解形式的统一事务管理---springboot

一前言 在操作数据库的时候,我们经常对一个service层进行事务设置,在springmvc中都是配置在xml文件中,在springboot中...

springBoot service层 事务控制

原文地址:https://www.cnblogs.com/tongxuping/p/7650293.html springBoot使用事物比较简单,在Applicati...

( 二十九 )、 SpringBoot 配置全局事务

( 二十九 )、 SpringBoot 配置全局事务 ( 二十九 )、 SpringBoot 配置全局事务     1、简介...