Home > Enterprise >  Error creating bean with name 'embeddedKafka' versions of Kafka
Error creating bean with name 'embeddedKafka' versions of Kafka

Time:07-26

getting:

Error creating bean with name 'embeddedKafka'

Caused by: java.lang.ClassNotFoundException: com.codahale.metrics.Reservoir

 <kafka.version>2.8.1</kafka.version>
 <spring.kafka.version>2.8.1</spring.kafka.version>

springboot version: 2.6.3 - can't be changed

        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-test</artifactId>

            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-kafka</artifactId>

        </dependency>
      
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
             <version>${spring.kafka.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>${spring.boot.version}</version>
            <scope>test</scope>
          
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka-test</artifactId>
            <version>${spring.kafka.version}</version>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
            <classifier>test</classifier>
            <scope>test</scope>
            <version>${kafka.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka_2.13</artifactId>
            <classifier>test</classifier>
            <scope>test</scope>
            <version>${kafka.version}</version>
        </dependency>

Where is the conflict? Maybe is some other dependency?

CodePudding user response:

You need to use Zookeeper 3.6.3; Kafka no longer pulls it in transitively.

CodePudding user response:

Please, follow instructions in the docs: https://docs.spring.io/spring-kafka/docs/2.8.1/reference/html/#update-deps.

Consider to use the latest Spring for Apache Kafka in that generation: https://spring.io/projects/spring-kafka#learn.

It looks like something brings incompatible Zookeeper version and we have a special comment for that in the docs for the mentioned version:

<!-- needed if downgrading to Apache Kafka 2.8.1 -->
<exclusions>
    <exclusion>
        <groupId>org.apache.zookeeper</groupId>
        <artifactId>zookeeper</artifactId>
    </exclusion>
</exclusions>

UPDATE

This pom works for me:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.3</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>so-73113638</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>so-73113638</name>
<description>so-73113638</description>
<properties>
    <java.version>1.8</java.version>
    <kafka.version>2.8.1</kafka.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.kafka</groupId>
        <artifactId>spring-kafka</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.kafka</groupId>
        <artifactId>spring-kafka-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

I just provide a kafka.version property and rely on the Spring Boot feature to manage deps for me.

  • Related