三个步骤:
1、初始化事务
2、事务提交
3、如果异常,事务回滚
代码示例:
1 @Autowired 2 private DataSourceTransactionManager dataSourceTransactionManager; 3 public void process() 4 { 5 TransactionStatus status = dataSourceTransactionManager.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW)); 6 //dosomething 7 dataSourceTransactionManager.commit(status); 8 }catch (Exception e) { 9 dataSourceTransactionManager.rollback(status); 10 //dosometing 11 }