Knowledge changes fate, stroke code makes me happy, 2020 continue to walk in the open source community click “like” to see, form a habit to give me a Star, click to understand the componentialized interface services based on SpringBoot landing solution

The project failed to start when integrating the Hoxton.sr5 version of the SpringCloud Gateway using ApiBoot’s latest release v2.2.5. The console threw the following error:

*************************** 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(NettyReactiveWebServ erFactory.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. Ja r! /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. The jar Action: Correct the classpath of your application so that it contains a single, compatible version of reactor.netty.tcp.TcpServerCopy the code

The error message printed from the console can be found to be caused by version incompatibility. As one of the important components of the SpringCloud Gateway, reactor-Netty is responsible for version incompatibility.

reactor-bom

When we build the project, SpringBoot uses the newly released V2.3.1 to define the reactor-BOM dependencies in the spring-boot-dependencies fixed version module, as shown below:

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

The ${reactor-bom} placeholder is dysprosium-sr8, and the reactor-netty version is v0.9.8, as shown below:

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

So why did the console throw an incompatibility issue with the REactor-Netty version v0.9.6 when we started the project?

The reactor-NetTY version that the project depends on

Check the External Libraries of the project in the IDEA development tool and find that the reactor-Netty version used in the project compilation is v0.9.6, as shown in the following figure:

The reactor-Netty version that the SpringCloud Gateway relies on

< span style = “box-sizing: border-box; color: RGB (74, 74, 74); line-height: 22px; font-size: 14px! Important; word-break: inherit! Important;” After opening the project using the IDEA tool and switching to the 2.2.x branch, you can find that the version of Reactory-Netty used in the External Libraries dependency list is V0.9.7, which is the version used to compile Spring-Cloud-Gateway.

The location of the spring-cloud-gateway repository on GitHub is [email protected]:spring-cloud/spring-cloud-gateway.git

Problem analysis

  1. From the above analysis steps, we can see that the reactory-Netty version used by Spring-Cloud-Gateway is V0.9.7, while the Reactory-netty version used by SpringBoot is V0.9.8. The dependent version supports backward compatibility, so there should be no problems.

  2. However, the version of Reactory-Netty used in our project compilation is V0.9.6, which must not support upward compatibility, so it led to the incompatible exception printed by the console when the project was started.

Problem orientation

The SpringCloud dependency is added by default in the hardened version of the ApiBoot dependency apI-boot-Dependencies to facilitate the use of components in projects integrating SpringCloud, but this also causes this problem.

The v2.2.5 ApiBoot integrates the SpringCloud version as Hoxton.release, which was released earlier than Hoxton.sr5 and uses the Reactory-Netty dependency version of V0.9.6.

To solve the problem

Now that we have identified the problem, we can easily fix it by changing the reactory-Netty version we are relying on to v0.9.6 or higher and adding the following dependencies to the pom.xml of the project:

<dependencyManagement>
  <! -- Omit other dependencies -->
  <dependencies>
    <dependency>
      <groupId>io.projectreactor.netty</groupId>
      <artifactId>reactor-netty</artifactId>
      <version>0.9.8</version>
    </dependency>
  </dependencies>
</dependencyManagement>
Copy the code

Author’s personal blog uses the open source framework ApiBoot to help you become an Api service architect