Jfianl aop 和 利用aop 自己定义一个Service异常

package cn.necsthz.cjzbapi.exception;

public class ServiceException extends RuntimeException {

    private static final long serialVersionUID = -717382329506444034L;

    private int code;
    private String errmsg;

    public ServiceException(int code, String errmsg) {
        this.code = code;
        this.errmsg = errmsg;
    }

    public int getCode() {
        return code;
    }

    public String getErrmsg() {
        return errmsg;
    }
}

=========================================================
@Before({ POST.class, Tx.class, DecryptParamsInterceptor.class })

========================================================
DecryptParamsInterceptor.class :


} catch (ServiceException ex) {
            JsonResult result = new JsonResult();
            result.code = ex.getCode();
            result.errmsg = ex.getErrmsg();
            ctl.renderJson(result);
            ctl.logger.error(ex.getErrmsg());
            throw new NestedTransactionHelpException(ex.getErrmsg());
=================================================================
Tx.class: 

   try {
            conn = config.getConnection();
            autoCommit = conn.getAutoCommit();
            config.setThreadLocalConnection(conn);
            conn.setTransactionIsolation(getTransactionLevel(config));    // conn.setTransactionIsolation(transactionLevel);
            conn.setAutoCommit(false);
            inv.invoke();
            conn.commit();
        } catch (NestedTransactionHelpException e) {
            if (conn != null) try {conn.rollback();} catch (Exception e1) {LogKit.error(e1.getMessage(), e1);}
            LogKit.logNothing(e);

你可能感兴趣的:(Jfianl aop 和 利用aop 自己定义一个Service异常)