dubbo全局异常处理_基于spring aop的dubbo异常统一处理
发布日期:2021-06-24 16:16:28 浏览次数:3 分类:技术文章

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

dubbo统一异常处理,调用方只显示封装后的异常。

1、返回封装后的Exception

2、返回封装后的统一返回信息

import org.aspectj.lang.annotation.AfterThrowing;

import org.aspectj.lang.annotation.Aspect;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.stereotype.Component;

import com.midea.jr.commons.utils.BeanUtils;

import com.midea.jr.efc.edp.common.bean.Response;

import com.midea.jr.efc.edp.common.enums.ResponseCodeEnum;

import com.midea.jr.efc.edp.common.exception.BizException;

/**

*

Project:

*

Module:

*

Description:

*

* @author wangzy25

* @date 2017年6月12日 上午10:07:58

*/

@Component

@Aspect

public class DubboExceptionInterceptor {

private static final Logger LOGGER = LoggerFactory.getLogger(DubboExceptionInterceptor.class);

@AfterThrowing(throwing="ex",pointcut="execution(* com.midea.jr.efc.edp.api.service.**.*(..))")

public BizException handle(Exception ex){

LOGGER.error("Intercept dubbo exception:{}", ex.getMessage(), ex);

if(ex instanceof BizException){

throw (BizException)ex;

}

//如果是非包装异常,则包装成统一的内部异常

throw new BizException(ResponseCodeEnum.EXCEPTION_INTERAL);

}

@AfterThrowing(throwing="ex",pointcut="execution(* com.midea.jr.efc.edp.api.service.**.*(..))")

public Response> handle(Exception ex){

Response> response = new Response<>();

LOGGER.error("intercept ServiceException:{}", ex.getMessage(), ex);

if(ex instanceof BizException){

BeanUtils.copyProperties( ex, response );

return response;

}

//如果是非包装异常,则包装成统一的内部异常

return new Response<>(ResponseCodeEnum.EXCEPTION_INTERAL);

}

}

转载地址:https://blog.csdn.net/weixin_33765959/article/details/111888200 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:主动断开socket链接_TCP连接与断开详解(socket通信)
下一篇:html5 拍照 分辨率,getUserMedia API及HTML5 调用手机摄像头拍照

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月16日 13时23分17秒