By default, spring affairs only happen when the uncaught RuntimeException rollback (a runtime exception).
Note, do not write and write try catch try {} catch (Exception e) {throw new RuntimeException ();} is the same meaning.
The figure below shows abnormal java system:
Solution:
- Not capture, capture or throw RuntimeException;
- Capture and manually rolled back,
try {
//orderDOMapper.insertSelective(orderDO);
} catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//手动回滚
//throw new BusinessException(EmBusinessError.PARAMETER_VALIDATION_ERROR,"重复秒杀!");
}
For the general user experience is good, I want to throw exceptions custom, will use the second solution, capture, and then manually rolled back, and then throw an exception customize.