【报错问题】java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode

情景:AOP获取请求参数,并转成JSON字符串时抛出

原因

ServletRequest,ServletResponse,MultipartFile不能被序列化,需要排除之后再做序列化。

示例: 

Object[] args = joinPoint.getArgs();
Object[] arguments  = new Object[args.length];
for (int i = 0; i < args.length; i++) {
  if (args[i] instanceof ServletRequest || args[i] instanceof ServletResponse || args[i] instanceof MultipartFile) {
                //ServletRequest不能序列化,从入参里排除,否则报异常:java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
                //ServletResponse不能序列化 从入参里排除,否则报异常:java.lang.IllegalStateException: getOutputStream() has already been called for this response
                continue;
  }
   arguments[i] = args[i];
}
paramter = JSONObject.toJSONString(arguments);
原文地址:https://www.cnblogs.com/stxyg/p/14964788.html