例如有业务需求,在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)