Spring 升级后 Kafka 错误 spring 启动到 2.6.6

Spring Kafka error after upgrading spring boot to 2.6.6

我将 spring 引导版本从 2.4.0 升级到 2.6.6(和 spring 云版本 2021.0.2)后遇到运行时错误。我的应用程序使用来自 kafka 主题的消息,并在经过一些转换后将其生成到另一个 kafka 主题。消息一被消耗,我就收到以下错误消息。

ERROR ERROR - - - - applog.cls=org.springframework.core.log.LogAccessor,applog.mthd=error,applog.line=149,applog.msg=Stopping container due to an Error,exc.stack=java.lang.NoSuchFieldError: LIFTER\n\tat org.springframework.cloud.sleuth.instrument.reactor.ReactorHooksHelper.getLifterName(ReactorHooksHelper.java:171)\n\tat org.springframework.cloud.sleuth.instrument.reactor.ReactorHooksHelper.isTraceContextPropagator(ReactorHooksHelper.java:175)\n\tat org.springframework.cloud.sleuth.instrument.reactor.ReactorHooksHelper.shouldDecorate(ReactorHooksHelper.java:121)\n\tat reactor.core.publisher.Operators$LiftFunction.apply(Operators.java:2488)\n\tat reactor.core.publisher.Operators$LiftFunction.apply(Operators.java:2449)\n\tat reactor.core.publisher.Flux.onAssembly(Flux.java:9692)\n\tat reactor.core.publisher.Flux.fromIterable(Flux.java:1118)\n\tat com.org.listener.MyListener.listen(MyListener.java:32)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:169)\n\tat org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:119)\n\tat org.springframework.kafka.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:56)\n\tat org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:339)\n\tat org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.invoke(BatchMessagingMessageListenerAdapter.java:180)\n\tat org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.onMessage(BatchMessagingMessageListenerAdapter.java:172)\n\tat org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.onMessage(BatchMessagingMessageListenerAdapter.java:61)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeBatchOnMessage(KafkaMessageListenerContainer.java:2268)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeBatchOnMessageWithRecordsOrList(KafkaMessageListenerContainer.java:2258)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeBatchOnMessage(KafkaMessageListenerContainer.java:2204)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeBatchListener(KafkaMessageListenerContainer.java:2114)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeBatchListener(KafkaMessageListenerContainer.java:1997)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeListener(KafkaMessageListenerContainer.java:1976)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeIfHaveRecords(KafkaMessageListenerContainer.java:1364)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.pollAndInvoke(KafkaMessageListenerContainer.java:1355)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:1247)\n\tat java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)\n\tat java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java)\n\tat java.lang.Thread.run(Thread.java:748)\n

我尝试检查 reactor-core ReactorHooksHelper.java 文件,但字段 LIFTER 似乎存在于那里。需要帮助来理解为什么服务会出现此错误。

反应器似乎有问题。您使用的 reactor-core 是哪个版本?对于 spring-boot 版本 2.6.6 尝试使用 reactor-core 版本 3.4.16

<dependency>
    <groupId>io.projectreactor</groupId>
    <artifactId>reactor-core</artifactId>
    <version>3.4.16</version>
</dependency>

您不应为 reactor-core 指定版本。 Spring-boot-dependencies 会为您处理好并自动使用 reactor-core 的 3.4.16。这就是使用 Spring Boot.

的美妙之处

查看此 POM 文件

https://search.maven.org/artifact/org.springframework.boot/spring-boot-dependencies/2.6.6/pom

并搜索 <reactor-bom.version>,注意版本是 2020.0.17

之后,找到等效的 reactor-bom 文件

https://search.maven.org/artifact/io.projectreactor/reactor-bom/2020.0.17/pom

并注意 reactor-core 的版本是 3.4.16

<dependency>
  <groupId>io.projectreactor</groupId>
  <artifactId>reactor-core</artifactId>
  <version>3.4.16</version>
</dependency>