在service层方法的catch语句中增长如下语句便可:ide
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
若是想自动处理,能够在指定的方法上添加如下注解便可:code
@Transactional