直接上代码
@Service
public class XXXService {
// 这两个必须要注入
@Resource
DataSourceTransactionManager dataSourceTransactionManager;
@Resource
TransactionDefinition transactionDefinition;
public void method1(){
// 开启事务
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
try{
//提交事务
dataSourceTransactionManager.commit(transactionStatus);
} catch (Exception e) {
// 回滚事务
dataSourceTransactionManager.rollback(transactionStatus);
}
}
}
标签:回滚,Resource,Spring,手动,boot,事务,dataSourceTransactionManager,transactionStatus
From: https://www.cnblogs.com/javaxubo/p/17498213.html