spring 事务是否会回滚的几种写法

//zh已测试通过


    @Transactional(rollbackFor=Exception.class) 
    public void methodName() {
       
       // 会回滚
       throw new Exception("...");
       
       // 会回滚
       throw new RuntimeException("...");


 
  
rollbackFor 默认就是 RuntimeException

@Transactional(rollbackFor= RuntimeException. class ) 或者是 @Transactional( )
public ItimDaoImpl getItemDaoImpl() {
        
       // 不会回滚
       throw new Exception("...");

// 会回滚  
      throw new RuntimeException("");   
  }    

你可能感兴趣的:(springmvc,spring)