项目中做切面日志类时,打印请求入参的代码报错
java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
org.apache.catalina.connector.Request.getAsyncContext(Request.java:1759)
org.apache.catalina.connector.RequestFacade.getAsyncContext(RequestFacade.java:1056)
com.alibaba.fastjson.serializer.ASMSerializer_1_RequestFacade.write(Unknown Source)
com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:310)
com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:288)
com.alibaba.fastjson.serializer.ObjectArrayCodec.write(ObjectArrayCodec.java:118)
com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:281)
com.alibaba.fastjson.JSON.toJSONString(JSON.java:673)
com.alibaba.fastjson.JSON.toJSONString(JSON.java:611)
com.alibaba.fastjson.JSON.toJSONString(JSON.java:576)
com.wh.mobile.common.log.ControllerLogAspect.logBeforeController(ControllerLogAspect.java:39)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
百度查到说是fastjson转换一些不支持序列化的类,于是在表单类中增加实现Serializable接口,能打印了
不过又发现入参中包含HttpServletRequest时还是不行,报同样错,应该是HttpServletRequest不支持序列化,于是找到了 这篇文章 https://my.oschina.net/mengzhang6/blog/2395893
里面写的解决方案是对不能序列化的类,单独过滤出来不做打印