切面打印日志时,参数序列化异常。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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步