使用kafka启动服务时出现java.lang.NoSuchMethodError。

问题描述 投票:0回答:1

我想做一个小的微服务项目来接触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个回答
0
投票

这是一个已知的问题,在这里报告。https:/github.comspring-cloudspring-cloud-releaseissues70。

你需要将Spring Integration Kafka的版本升级到2.1.0来解决这个问题。


0
投票

通过外部依赖解决

<dependency>
        <groupId>org.springframework.kafka</groupId>
        <artifactId>spring-kafka</artifactId>
        <version>2.4.6.RELEASE</version>
    </dependency>
© www.soinside.com 2019 - 2024. All rights reserved.