切面打印日志时,参数序列化异常。It is illegal to call this method if the current request is not in asynchron

切面打印日志时,参数序列化异常

异常信息:It is illegal to call this method if the current request is not in asynchron

原因

joinPoint.getArgs()返回的数组中携带有Request或者Response对象,导致序列化异常

切面打印日志时,参数序列化异常。It is illegal to call this method if the current request is not in asynchron_第1张图片

解决

		Object[] args = joinPoint.getArgs();
        Stream stream = ArrayUtils.isEmpty(args) ? Stream.empty() : Arrays.asList(args);
        List logArgs = stream
                .filter(arg -> (!(arg instanceof HttpServletRequest) && !(arg instanceof HttpServletResponse)))
                .collect(Collectors.toList());
          //过滤后序列化无异常
        String string = JSON.toJSONString(logArgs);
              







你可能感兴趣的:(java)