zoukankan      html  css  js  c++  java
  • Aop 打印参数日志时,出现参数序列化异常。It is illegal to call this method if the current request is not in asynchron

    错误信息:

    nested exception is java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)] with root cause:
    错误原因:

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

    解决方案:

    //aop中获取请求参数

    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);

  • 相关阅读:
    句子
    Https
    SSH
    uCMDB
    snapshot与release
    Ansible
    .NET core webApi 使用JWT验证签名(转)
    .NET core 使用Swagger(转)
    微服务的4个设计原则和19个解决方案(转)
    .NET Core 使用RabbitMQ(转)
  • 原文地址:https://www.cnblogs.com/ming-blogs/p/11648988.html
Copyright © 2011-2022 走看看