如何手动开启事务?

@Autowiredprivate 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);

posted @ 2019-09-05 11:25  梦人亭  阅读(2993)  评论(0编辑  收藏  举报