@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;
}
标签:BaseResp,回滚,null,service,resp,手动,Exception,transactionStatus,transactionManager
From: https://blog.51cto.com/u_14816966/8689163