前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >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

作者头像
itze
发布2022-10-31 16:25:11
1.6K0
发布2022-10-31 16:25:11
举报
文章被收录于专栏:IT者IT者

问题

在使用切面+自定义注解实现日志记录时报的错

原因

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

解决

过滤掉之后再转换

代码语言:javascript
复制
        //获取传参信息
        Object[] args = proceedingJoinPoint.getArgs();
        //过滤无法序列化
        Stream<?> stream = ArrayUtils.isEmpty(args) ? Stream.empty() : Arrays.stream(args);
        List<Object> logArgs = stream
                .filter(arg -> (!(arg instanceof HttpServletRequest) && !(arg instanceof HttpServletResponse)))
                .collect(Collectors.toList());
        //过滤后序列化无异常
        String requestParam = JSON.toJSONString(logArgs);
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022年7月8日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 问题
  • 原因
  • 解决
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档