除了用 @Transactional 外还可以手工调用
PlatformTransactionManager transactionManager = (PlatformTransactionManager)SpringBeanUtil.getBean(PlatformTransactionManager.class); DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition(); transactionDefinition.setPropagationBehavior(Propagation.REQUIRED.value()); TransactionStatus transaction = null; Object result; try { transaction = transactionManager.getTransaction(transactionDefinition); // 业务代码 transactionManager.commit(transaction); } catch (Exception ex) { if (null != transaction && !transaction.isCompleted()) { transactionManager.rollback(transaction); } throw ex; } finally { if (null != transaction && !transaction.isCompleted()) { transactionManager.rollback(transaction); } }
标签:Transaction,手工,transactionDefinition,transaction,调用,PlatformTransactionManager,n From: https://www.cnblogs.com/zhshlimi/p/17928008.html