1.注入
@Autowired
private DataSourceTransactionManager dstManager
2.
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别,开启新事务,这样会比较安全些。
TransactionStatus transaction= dstManager.getTransaction(def); // 获得事务状态
3.提交事务
dstManager.commit(transaction);
4.回滚事务
dstManager.rollback(transaction);