Kannan Ekanath
Kannan Ekanath

Reputation: 17601

Spring boot embedded Kafka integration throws NoClassDefFoundError

Spring Boot: 2.0.3.RELEASE

org.apache.kafka.kafka-streams: 1.0.0

org.apache.kafka.kafka-clients: 1.0.0

org.springframwork.kafka:spring-kafka-test:2.1.7.RELEASE

I have a working Spring boot application with Kafka. I am trying to follow https://blog.mimacom.com/testing-apache-kafka-with-spring-boot/ to create an integration test.

When I add the @EmbeddedKafka annotation I get the error when I run

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaEmbedded': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/kafka/common/record/RecordFormat
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:407) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]

There are a few google results on this error however they are all on old kafka-client versions and they should be fixed in the version I use.

This looks like a version mismatch but it is not clear to me what I am supposed to me.

Upvotes: 2

Views: 6409

Answers (1)

Kannan Ekanath
Kannan Ekanath

Reputation: 17601

As indicated in comments errors like these are always due to library version incompatibilities. The following combination worked

spring boot: 2.1
spring-streams/spring-client: 2.0.1 (Using 2.2.0 creates some compatibility issues)
spring-kafka: 2.2.5.RELEASE

Upvotes: 1

Related Questions