切面打印日志时,参数序列化异常。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 @   King-DA  阅读(1655)  评论(1编辑  收藏  举报
编辑推荐:
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
阅读排行:
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 用 C# 插值字符串处理器写一个 sscanf
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!
历史上的今天:
2019-03-26 AdminLTE模板使用
2019-03-26 SVN的标准目录结构
2019-03-26 Subversion版本控制系统的安装和操作.
点击右上角即可分享
微信分享提示