切面打印日志时,参数序列化异常。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);
本文来自博客园,作者:King-DA,转载请注明原文链接:https://www.cnblogs.com/qingmuchuanqi48/p/14581913.html