为GraphQL(WebMvc)启用或禁用Spring中的异步模式



使用org.springframework.boot:spring-boot-starter-graphql和WebMvc,运行查询时出现以下错误:Caused by: java.lang.IllegalStateException: Async support must be enabled on a servlet and for all filters involved in async request processing. This is done in Java code using the Servlet API or by adding "<async-supported>true</async-supported>" to servlet and filter declarations in web.xml.

  1. 我们可以为GraphQL禁用Spring中的异步模式吗
  2. 如果没有,如何在Spring中为GraphQL端点启用async-supported

异步调度不能用简单的属性禁用,也不建议这样做,因为GraphQLJava默认使用AsyncExecutionStrategy。我想说,这是GraphQL方法的核心,在GraphQL中,模式的部分可以从多个源(数据存储、web API等(解析,并且引擎对此进行了优化。

如果您收到这个错误,这意味着您已经配置了一个自定义过滤器,该过滤器没有配置为异步支持(并且仍然映射为async调度(。一般来说,您应该检查您的整个过滤器/Servlet/容器安排,以进行检查。理想情况下,你可以从一个新的开始https://start.spring.io并逐个添加自定义筛选器和配置。

最新更新