使用kafka启动服务时发生java.lang.nosuchmethoderror

k4emjkb1  于 2021-06-05  发布在  Kafka
关注(0)|答案(2)|浏览(520)

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

我们能做些什么来修复它?谢谢!

yx2lnoni

yx2lnoni1#

这是一个已知的问题,报告如下:https://github.com/spring-cloud/spring-cloud-release/issues/70
您需要将SpringIntegrationKafka的版本升级到2.1.0才能解决此问题。

hk8txs48

hk8txs482#

通过外部依赖解决

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

相关问题