1. 程式人生 > >spring手動回滾事務

spring手動回滾事務

@Transactional(rollbackFor = { Exception.class })
public String methods() {
        String str = "-----------";
        try {
            doSomethings......
        } catch (Exception e) {
            logger.error("e.getMessage()", e);
            //手動開啟事務回滾
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); 
        }
        return str;
    }