配置事务
<!-- (事务管理) -->
<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />
注入文件
@Autowired
private DataSourceTransactionManager transactionManager;
//1.获取事务定义
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
//2.设置事务隔离级别,开启新事务
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
//3.获得事务状态
TransactionStatus status = transactionManager.getTransaction(def);
// 事务回滚
transactionManager.rollback(status);
// 事务提交
transactionManager.commit(status);
标签:status,回滚,spring,手动,事务,DefaultTransactionDefinition,def,transactionManager
From: https://blog.51cto.com/u_15993308/6193863