问题与处理策略
问题描述
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.8</version>
<relativePath/>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
- 在 Spring Boot 项目中,使用 WebFlux 时,报如下错误
***************************
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:
reactor.netty.transport.logging.ReactorNettyLoggingHandler.<init>(ReactorNettyLoggingHandler.java:65)
The following method did not exist:
io.netty.handler.logging.LoggingHandler.<init>(Ljava/lang/String;Lio/netty/handler/logging/LogLevel;Lio/netty/handler/logging/ByteBufFormat;)V
The calling method's class, reactor.netty.transport.logging.ReactorNettyLoggingHandler, was loaded from the following location:
jar:file:/D:/Maven/repository/io/projectreactor/netty/reactor-netty-core/1.0.19/reactor-netty-core-1.0.19.jar!/reactor/netty/transport/logging/ReactorNettyLoggingHandler.class
The called method's class, io.netty.handler.logging.LoggingHandler, is available from the following locations:
jar:file:/D:/Maven/repository/io/netty/netty-all/4.1.39.Final/netty-all-4.1.39.Final.jar!/io/netty/handler/logging/LoggingHandler.class
jar:file:/D:/Maven/repository/io/netty/netty-handler/4.1.77.Final/netty-handler-4.1.77.Final.jar!/io/netty/handler/logging/LoggingHandler.class
The called method's class hierarchy was loaded from the following locations:
io.netty.handler.logging.LoggingHandler: file:/D:/Maven/repository/io/netty/netty-all/4.1.39.Final/netty-all-4.1.39.Final.jar
io.netty.channel.ChannelDuplexHandler: file:/D:/Maven/repository/io/netty/netty-all/4.1.39.Final/netty-all-4.1.39.Final.jar
io.netty.channel.ChannelInboundHandlerAdapter: file:/D:/Maven/repository/io/netty/netty-all/4.1.39.Final/netty-all-4.1.39.Final.jar
io.netty.channel.ChannelHandlerAdapter: file:/D:/Maven/repository/io/netty/netty-all/4.1.39.Final/netty-all-4.1.39.Final.jar
Action:
Correct the classpath of your application so that it contains compatible versions of the classes reactor.netty.transport.logging.ReactorNettyLoggingHandler and io.netty.handler.logging.LoggingHandler
# 翻译
***************************
应用程序启动失败
***************************
描述:
尝试调用一个不存在的方法,调用发生在以下位置:
reactor.netty.transport.logging.ReactorNettyLoggingHandler.<init>(ReactorNettyLoggingHandler.java:65)
以下方法不存在:
io.netty.handler.logging.LoggingHandler.<init>(Ljava/lang/String;Lio/netty/handler/logging/LogLevel;Lio/netty/handler/logging/ByteBufFormat;)V
调用方的类(reactor.netty.transport.logging.ReactorNettyLoggingHandler)从以下位置加载:
jar:file:/D:/Maven/repository/io/projectreactor/netty/reactor-netty-core/1.0.19/reactor-netty-core-1.0.19.jar!/reactor/netty/transport/logging/ReactorNettyLoggingHandler.class
被调用方的类继承关系从以下位置加载:
io.netty.handler.logging.LoggingHandler: file:/D:/Maven/repository/io/netty/netty-all/4.1.39.Final/netty-all-4.1.39.Final.jar
io.netty.channel.ChannelDuplexHandler: file:/D:/Maven/repository/io/netty/netty-all/4.1.39.Final/netty-all-4.1.39.Final.jar
io.netty.channel.ChannelInboundHandlerAdapter: file:/D:/Maven/repository/io/netty/netty-all/4.1.39.Final/netty-all-4.1.39.Final.jar
io.netty.channel.ChannelHandlerAdapter: file:/D:/Maven/repository/io/netty/netty-all/4.1.39.Final/netty-all-4.1.39.Final.jar
操作:
修正应用程序的类路径,确保包含兼容版本的以下类:
- reactor.netty.transport.logging.ReactorNettyLoggingHandler
- io.netty.handler.logging.LoggingHandler
问题原因
- Spring Boot 中的 WebFlux,默认依赖 Reactor Netty 作为底层 HTTP 服务器和客户端实现



-
ReactorNettyLoggingHandler(来自
reactor-netty-core:1.0.19
)尝试调用 LoggingHandler(来自netty-all:4.1.39
)的一个构造方法 -
但是,项目中混入了 不兼容的 Netty 版本,该构造方法在当前的 Netty 版本中不存在,因此报错
处理策略
- 完全移除 Netty,Spring Boot 已自动管理 Netty 依赖,无需单独声明,这样可以使用统一的 Netty 版本
<!-- 移除这段配置 -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.39.Final</version>
</dependency>