在过滤器里打印日志报如下错误(大概意思是请求不是同步的)怎么回事?

com.alibaba.fastjson.JSONException: toJSON error
com.alibaba.fastjson.JSON.toJSON(JSON.java:987)
com.alibaba.fastjson.JSON.toJSON(JSON.java:888)
。。。。。。
root cause

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:1695)
org.apache.catalina.connector.RequestFacade.getAsyncContext(RequestFacade.java:1055)

我写的代码如下:
public class TestFilter implements Filter {
static final Logger logger = LoggerFactory.getLogger(TestFilter.class);
public void init(FilterConfig filterConfig) throws ServletException {
}

//新建一个装饰者模式的request对象,以便对request对象的参数进行更改/过滤
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    logger.info("请求为:{}",JSON.toJSON(request));
    chain.doFilter(request, response);//对request和response进行过滤
}


public void destroy() {

}

}

https://blog.csdn.net/evilcry2012/article/details/78864528

使用fastJson将对象转化为JSON字符串,对象必须实现序列化接口,而ServletRequest只是抽象类,并且没有实现序列化接口,所以不可能转成JSON字符串

首先,建议logger.info("请求为:{}",JSON.toJSON(request));
这行打印信息去掉吧,通常只需要打印request.URL请求路径即可了,没有必要转换为JSON字符串
其次,异常信息来看应该是toJSON操作触发了Servlet的某种状态检查导致的该异常。

大概是你调用了异步servlet的相关方法,比如request.startAsync(),但是servlet本身的异步性支持开关没打开:

 <async-supported>true</async-supported>