博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring-dubbo 异常统一捕获
阅读量:4229 次
发布时间:2019-05-26

本文共 1605 字,大约阅读时间需要 5 分钟。

import com.sf.framework.exceptions.BaseServiceException;import org.aspectj.lang.ProceedingJoinPoint;import org.aspectj.lang.annotation.Around;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Pointcut;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.stereotype.Component;@Component@Aspectpublic class ServiceExceptionHandler {    /**     * 指定返回值为Response类型的Service     */    @Pointcut(value = "execution(* com.xxx.service.MasterRestService.*(..))")    private void servicePointcut() {        // Do nothing just pointcut    }    /**     * 异常处理切面     * 将异常包装为Response,避免dubbo进行包装     *     * @param pjp 处理点     * @return 返回异常处理结果     */    @Around("servicePointcut()")    public Object doAround(final ProceedingJoinPoint pjp) {        final Logger logger = LoggerFactory.getLogger(pjp.getTarget().getClass());        final Object[] args = pjp.getArgs();        final String log = String.format("\n%s ****** with params: {}", pjp.toShortString());        try {            logger.info(log, args);            return pjp.proceed();        } catch (Throwable e) {            logger.error(log, args);            logger.error("\n*************Exception*************", e);            if (e instanceof BaseServiceException) {                BaseServiceException be = (BaseServiceException) e;                return ResponseUtil.buildFailedRsp(be.getErrorCode(), be.getMessage(), VersionUtil.V_4_1);            } else {                return ResponseUtil.buildFailedRsp(ErrorCodes.OTHER_EXCEPTION_9999, "未知异常", VersionUtil.V_4_1);            }        }    }}

 

转载地址:http://daiqi.baihongyu.com/

你可能感兴趣的文章
求一个整数数组中第二大的数
查看>>
删除一个链表中的节点
查看>>
计算机网络面试整理【转】
查看>>
cookie和session区别详解
查看>>
程序员失业第一步?斯坦福研究员用AI从编译器反馈中学习改Bug
查看>>
原创 | 电视广告流量预测中的“常识”陷阱,你掉进去了吗?
查看>>
DeepMind发布最新《神经网络中持续学习》综述论文!
查看>>
本科三篇顶会一作、超算竞赛冠军,2020清华本科特奖结果出炉
查看>>
多语言互通:谷歌发布实体检索模型,涵盖超过100种语言和2000万个实体
查看>>
你的房东可能正用AI筛查你的犯罪记录,决定要不要租房给你
查看>>
AI把爱豆变胖视频火遍B站,我们找到了背后的技术团队:你是怎么把刘亦菲变胖的?...
查看>>
白硕:区块链技术与数据隐私(附视频)
查看>>
数据蒋堂 | 报表工具的SQL植入风险
查看>>
AAC ADTS LATM 格式分析
查看>>
【转载】嵌入式系统 Boot Loader 技术内幕
查看>>
【转载】uboot学习笔记
查看>>
分布式消息中间件(rabbitMQ篇)
查看>>
JAVA程序员养成计划之JVM学习笔记(2)-垃圾收集管理
查看>>
JAVA程序员养成计划之JVM学习笔记(3)-JVM性能监控
查看>>
POJ 3580
查看>>