spring 声明式事务

     此文只是记录一下,如有问题给我留言。
    
TransactionTemplate template  =   new  TransactionTemplate(transactionManager);
            template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
            template.execute(
new  TransactionCallbackWithoutResult()  {
                @Override
                
protected void doInTransactionWithoutResult(TransactionStatus status) {
                    
                        testDao.save(obj);
                    
                }

                
            }
);

 异常需要在外层catch 因为提交时在transaction而不是save炒作。
 
声明式事务主要用于:
  1:相对于配置式
 2:要将长事务分成小事务,在此期间其他事务将挂起(Suspend )直到当前事务提交完成

 

---------

你可能感兴趣的:(spring 声明式事务)