前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ApiBoot v2.2.5版本无法兼容Hoxton.SR5的SpringCloud Gateway

ApiBoot v2.2.5版本无法兼容Hoxton.SR5的SpringCloud Gateway

作者头像
恒宇少年
发布2020-06-22 19:56:55
6660
发布2020-06-22 19:56:55
举报

使用ApiBoot最新发布的v2.2.5版本整合SpringCloud GatewayHoxton.SR5版本时导致项目无法启动,控制台抛出的错误如下所示:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory.lambda$createHttpServer$0(NettyReactiveWebServerFactory.java:158)

The following method did not exist:

    reactor.netty.tcp.TcpServer.bindAddress(Ljava/util/function/Supplier;)Lreactor/netty/tcp/TcpServer;

The method's class, reactor.netty.tcp.TcpServer, is available from the following locations:

    jar:file:/Users/yuqiyu/.m2/repository/io/projectreactor/netty/reactor-netty/0.9.6.RELEASE/reactor-netty-0.9.6.RELEASE.jar!/reactor/netty/tcp/TcpServer.class

The class hierarchy was loaded from the following locations:

    reactor.netty.tcp.TcpServer: file:/Users/yuqiyu/.m2/repository/io/projectreactor/netty/reactor-netty/0.9.6.RELEASE/reactor-netty-0.9.6.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of reactor.netty.tcp.TcpServer

从控制台打印的错误信息我们可以发现这是版本不兼容的问题导致的,reactor-netty作为SpringCloud Gateway的重要组成部分之一,为什么会出现版本不兼容的问题呢?

reactor-bom

我们在构建项目时,SpringBoot使用最新发布的v2.3.1,在v2.3.1版本的spring-boot-dependencies固化版本依赖模块内定义reactor-bom的依赖,如下所示:

<dependency>
  <groupId>io.projectreactor</groupId>
  <artifactId>reactor-bom</artifactId>
  <version>${reactor-bom.version}</version>
  <type>pom</type>
  <scope>import</scope>
</dependency>

${reactor-bom}占位符对应的使用版本为Dysprosium-SR8,通过查看reactor-bom内定义的依赖列表发现了reactor-netty的踪迹,而它对应的版本为v0.9.8,如下所示:

<dependency>
  <groupId>io.projectreactor.netty</groupId>
  <artifactId>reactor-netty</artifactId>
  <version>0.9.8.RELEASE</version>
</dependency>

那为什么我们在启动项目时控制台抛出了使用v0.9.6版本的reactor-netty导致不兼容的问题呢?

项目依赖的reactor-netty版本

查看idea开发工具内项目的External Libraries发现,项目编译时使用的reactor-netty的版本确实是为v0.9.6,如下图所示:

SpringCloud Gateway依赖的reactor-netty版本

Hoxton.SR5版本的spring-cloud-dependencies依赖内使用的spring-cloud-gateway版本为2.2.3.RELEASE,我们从GitHub拉取spring-cloud-gateway源码到本地,使用idea工具打开项目并切换到2.2.x分支后发现External Libraries依赖列表内所使用的reactory-netty版本为v0.9.7这是编译spring-cloud-gateway时所依赖的版本

spring-cloud-gateway仓库在GitHub的地址为:git@github.com:spring-cloud/spring-cloud-gateway.git

问题分析

  1. 从上面的分析步骤中我们发现,spring-cloud-gateway编译时所使用的reactory-netty版本为v0.9.7,而v2.3.1版本的SpringBoot所使用的reactory-netty版本为v0.9.8,依赖的版本是支持向下兼容的,所以这样不会出现什么问题。
  2. 但是我们项目在编译时使用的reactory-netty版本却为v0.9.6,版本肯定是不支持向上兼容的,所以才导致了项目启动时控制台打印的不兼容异常。

问题定位

ApiBoot的固化版本依赖api-boot-dependencies内默认添加了SpringCloud的依赖,为了方便项目集成SpringCloud时使用组件,不过这也导致了这个问题的发生。

v2.2.5版本的ApiBoot内集成的SpringCloud版本为Hoxton.RELEASE,要比Hoxton.SR5版本发布的更早,它所使用的reactory-netty依赖版本为v0.9.6

解决问题

既然找到了问题,对症下药,解决起来就容易了,我们只需要把项目中所依赖的reactory-netty版本修改为v0.9.6以上版本即可,在项目的pom.xml内添加如下依赖:

<dependencyManagement>
  <!--省略其他依赖-->
  <dependencies>
    <dependency>
      <groupId>io.projectreactor.netty</groupId>
      <artifactId>reactor-netty</artifactId>
      <version>0.9.8</version>
    </dependency>
  </dependencies>
</dependencyManagement>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • reactor-bom
  • 项目依赖的reactor-netty版本
  • SpringCloud Gateway依赖的reactor-netty版本
  • 问题分析
  • 问题定位
  • 解决问题
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档