在service層方法的catch語句中增長如下語句便可:ide
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
若是想自動處理,能夠在指定的方法上添加如下註解便可:code
@Transactional