@Autowired private PlatformTransactionManager transactionManager;
try的整个方法-catch
public BaseResp xxx() throws Exception{ BaseResp resp = new BaseResp(); TransactionStatus transactionStatus = null; try{ transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition()); ///其他处理 //... transactionManager.commit(transactionStatus); }catch(Exception e){ if (transactionStatus != null) { transactionManager.rollback(transactionStatus); } throw e; } return resp;}