切面打印日志时,参数序列化异常。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对象,导致序列化异常

 

 

 

解决

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

 

posted @ 2021-03-26 13:32  King-DA  阅读(1607)  评论(1编辑  收藏  举报