@Transactional注释的替代项



除了@Transactional annotation之外,spring中回滚事务的替代方案是什么。我已经使用了这个注释,但我想要在catch块中回滚事务的方式。有办法吗?

提前Thanx。

这是一份草案:

public class SomeService implements SomeInterface {
   private SomeDao thisDaoWrapsJdbcTemplate;
   private PlatformTransactionManager transactionManager;
   public void setTransactionManager( PlatformTransactionManager transactionManager ) {
      this.transactionManager = transactionManager;
   }
   public void doBusiness( Business: business ) {
      TransactionDefinition def = new DefaultTransactionDefinition();
      TransactionStatus status = transactionManager.getTransaction( def );
      try {
         // do business here
         Money money = Money.LOTS_OF
         ...
         // wire the money in..
         thisDaoWrapsJdbcTemplate.depositLotsOfMoney( money )
         transactionManager.commit( status );
      } catch ( DataAccessException dae ) {
         transactionManager.rollback( status );
         throw dae;
      }
      return;
   }

相关内容

  • 没有找到相关文章

最新更新