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