You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot GraphQL自动配置启动时无法实例化GraphQlSource问题

问题描述

我有一个基于Spring WebFlux和Spring GraphQL的Spring Boot应用,启动时自动配置机制无法实例化graphQlSource Bean,底层依赖的工厂方法执行失败,错误日志如下:

Factory method 'graphQlSource' threw exception with message: Error creating bean with name 'annotatedControllerConfigurerDataFetcherExceptionResolver' defined in class path resource [org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfiguration.class]: Unsatisfied dependency expressed through method 'annotatedControllerConfigurerDataFetcherExceptionResolver' parameter 0: Error creating bean with name 'annotatedControllerConfigurer' defined in class path resource [org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfiguration.class]: Error creating bean with name 'cursorStrategy' defined in class path resource [org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfiguration$GraphQlDataAutoConfiguration.class]: Failed to instantiate [org.springframework.graphql.data.pagination.EncodingCursorStrategy]: Factory method 'cursorStrategy' threw exception with message: com/fasterxml/jackson/annotation/JsonTypeInfo$Value

我已检查Maven依赖树,但未发现引发问题的库版本冲突。当前使用的版本信息:

  • Spring Boot 3.1.7
  • Spring WebFlux 6.0.15
  • Spring GraphQL 1.2.4(通过spring-boot-starter-graphql 3.1.7引入)
解决方案建议
  1. 显式锁定Jackson依赖版本
    Spring Boot 3.1.x默认适配Jackson 2.15.x版本,可能存在隐式依赖导致版本不一致。在pom.xml中直接声明Jackson核心依赖,强制统一版本:
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.15.3</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.15.3</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.15.3</version>
</dependency>
  1. 清理并重新构建依赖
    执行Maven命令清理本地缓存,重新拉取完整依赖:
mvn clean install -U
  1. 排查自定义Jackson配置
    如果项目中有自定义Jackson配置类,确认未移除或修改JsonTypeInfo相关注解的支持,避免干扰Spring GraphQL内部的序列化逻辑。

  2. 简化依赖引入方式
    尝试直接引入Spring Boot官方starter,让框架自动管理所有依赖版本,减少手动指定版本引发的兼容性问题:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-graphql</artifactId>
</dependency>

内容的提问来源于stack exchange,提问作者Fabien Coppens

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 02:25:01