java.lang.NoSuchMethodError 在使用 kafka 启动服务期间

java.lang.NoSuchMethodError during service startup with kafka

我正在尝试制作一个小型微服务项目来接触 kafka。 要启动 kafka,我正在使用 docker compose:

  kafka-server:
image: spotify/kafka
ports:
- 2181:2181
- 9092:9092
environment:
  ADVERTISED_PORT: 9092
  CONSUMER_THREADS: 1
  TOPICS: serverInputTopic,clientInputTopic

为了在我的服务中添加 kafka 支持,我在 POM 中使用了以下内容

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.2.RELEASE</version>
    <relativePath/>
</parent>
<properties>
    <spring-cloud.version>Hoxton.SR3</spring-cloud.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-stream-kafka</artifactId>
    </dependency>
</dependencies>

只有代码中的用法是对运行器的注释class

@EnableBinding(Sink.class)

和监听器方法的注解

@StreamListener(Sink.INPUT)

我启动 kafka 没有问题,但是当我启动我的服务时出现以下错误:

    ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: F
ailed to start bean 'inputBindingLifecycle'; nested exception is java.lang.NoSuchMethodError: org.springframework.kafka.listener.ContainerProperties.setAuthorizationExceptionRetryInterval(Ljava/time/Duration;)V

如何解决?谢谢!

这是此处报告的已知问题:https://github.com/spring-cloud/spring-cloud-release/issues/70

您需要将Spring Integration Kafka的版本升级到2.1.0才能解决问题。

解决了外部依赖

<dependency>
        <groupId>org.springframework.kafka</groupId>
        <artifactId>spring-kafka</artifactId>
        <version>2.4.6.RELEASE</version>
    </dependency>