运行Spring项目时出现reactor.netty ConnectionProvider$Builder类路径错误如何解决
问题成因
- 该错误属于典型的依赖版本不兼容导致的
NoSuchMethodError:你当前加载的reactor-netty 0.9.12.RELEASE版本中,reactor.netty.resources.ConnectionProvider$Builder类的evictInBackground方法签名,与Spring Cloud Gateway调用该方法时预期的签名不匹配。0.9.12.RELEASE版本的该方法返回值为Builder本身,而你使用的Spring Cloud Gateway版本要求该方法返回ConnectionProvider$ConnectionPoolSpec类型,调用时无法找到匹配的方法导致启动失败。 - 触发原因是项目类路径下存在多版本的reactor-netty依赖,Maven依赖仲裁机制优先加载了低版本的0.9.12.RELEASE,无法满足Spring Cloud Gateway的版本要求。
处理方案
- 第一步:核对Spring Boot、Spring Cloud的版本匹配关系,确保Spring Cloud Gateway的版本与Spring Cloud父版本完全一致,不要单独引入跨版本的Gateway依赖。
- 第二步:排查reactor-netty的依赖冲突,执行Maven命令
mvn dependency:tree -Dincludes=io.projectreactor.netty:reactor-netty,定位所有引入reactor-netty的依赖节点,对引入了低版本reactor-netty的依赖添加排除规则:
<dependency> <groupId>冲突依赖的groupId</groupId> <artifactId>冲突依赖的artifactId</artifactId> <exclusions> <exclusion> <groupId>io.projectreactor.netty</groupId> <artifactId>reactor-netty</artifactId> </exclusion> </exclusions> </dependency>
- 第三步:手动声明符合版本要求的reactor-netty依赖,确保版本与Spring Cloud版本兼容:
- Spring Cloud Hoxton版本:使用reactor-netty 0.9.25.RELEASE及以上的0.9.x分支版本
- Spring Cloud 2020.0.x及以上版本:使用reactor-netty 1.0.x及以上分支版本
- 第四步:清理本地Maven缓存后重新构建,执行命令
mvn clean install -U强制刷新依赖,避免本地缓存的旧jar包干扰。
内容的提问来源于stack exchange,提问作者samarth khandelwal
相关产品推荐
相关产品推荐

