【问题标题】:java.lang.NoSuchMethodError during service startup with kafka使用kafka启动服务期间的java.lang.NoSuchMethodError
【发布时间】:2020-04-28 06:44:31
【问题描述】:

我正在尝试制作一个小型微服务项目来接触 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>

只有在代码中的用法是 runner 类上的注解

@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

可以做些什么来解决它?谢谢!

【问题讨论】:

    标签: spring-boot apache-kafka spring-cloud


    【解决方案1】:

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

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

    【讨论】:

    • 嗨,这是不同的问题。而且我已经有了 spring-integration-kafka:3.2.1.RELEASE
    【解决方案2】:

    通过外部依赖解决

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

    【讨论】:

      猜你喜欢
      • 2021-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-23
      • 1970-01-01
      • 2012-10-14
      • 2013-01-30
      • 1970-01-01
      相关资源
      最近更新 更多