第一步:配置实现MethodInterceptor的切面
java代码
1 public class OutsideInvokeLogInterceptor implements MethodInterceptor{ 2 private static Logger log = Logger.getLogger("outsideInvoke"); 3 4 @Override 5 public Object invoke(MethodInvocation invocation) throws Throwable { 6 String methodName = invocation.getMethod().toString(); 7 Object returnValue = invocation.proceed(); 8 if (returnValue == null) { 9 log.warn("调用 " + methodName + "is fail,返回的result结果为空,方法入参为:(" + parseArguments(invocation.getArguments()) + ")"); 10 return ResultDTO.getFailureResult(BSErrorCode.INTERNAL_ERROR, BaseKeyMsgCode.RETURN_RESULTDTO_IS_NULL); 11 }else{ 12 if(returnValue instanceof ResultDTO){ 13 ResultDTO<Object> resultDTO = (ResultDTO<Object>)returnValue; 14 if(!resultDTO.isSuccess()){ 15 log.warn("调用 " + methodName + " is fail ,方法入参为:(" + parseArguments(invocation.getArguments()) + ")" 16 + "返回值:" +resultDTO.getCode() + "," + resultDTO.getKey()); 17 } else{ 18 log.info("调用 " + methodName + " is success ,方法入参为:(" + parseArguments(invocation.getArguments()) + ")"); 19 } 20 } 21 } 22 return returnValue; 23 24 } 25 }