java.lang.IllegalStateException: It is illegal to call this method if the current request is not in

2021/7/2 20:51:22

本文主要是介绍java.lang.IllegalStateException: It is illegal to call this method if the current request is not in,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

情景: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);

 



这篇关于java.lang.IllegalStateException: It is illegal to call this method if the current request is not in的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程