Spring 实现部分事务回滚

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

1
2
3
4
5
6
7
8
9
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 @   ゞ清茶℡  阅读(4556)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示