Spring 实现部分事务回滚

例如有业务需求,在catch异常后,catch块内把异常的信息存入到数据库,而catch外的数据全部回滚

try {
  .......
   aaaService.save();
 
}catch(RuntimeException e) {

    bbbService.save(e.getMessage());
    throw new RuntimeException(e.getMessage());
}

 确保aaaService.save()的数据回滚,而 bbbService的save不回滚。

只能在bbbService save的头部加上开启新的事务即可

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Exception.class)
posted @ 2017-07-19 21:30  ゞ清茶℡  阅读(4460)  评论(0编辑  收藏  举报