I am trying to make a small microservices project to touch kafka. To start kafka I am using docker compose:
kafka-server:
image: spotify/kafka
ports:
- 2181:2181
- 9092:9092
environment:
ADVERTISED_PORT: 9092
CONSUMER_THREADS: 1
TOPICS: serverInputTopic,clientInputTopic
To add kafka support in my service I use following in 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>
Only usage in code is annotation on runner class
@EnableBinding(Sink.class)
and annotation on listener method
@StreamListener(Sink.INPUT)
I start kafka without problems, but when I start my service I get following error:
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
What can be done to fix it? Thanks!
resolved with external dependency
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>2.4.6.RELEASE</version>
</dependency>