Spring Integration Kafka ClassNotFoundException:KafkaHeaderMapper

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

在使用spring-integration-kafka库运行Spring Boot应用程序时,我收到以下错误:

引起:java.lang.ClassNotFoundException:org.springframework.kafka.support.KafkaHeaderMapper

在以下方法的主体的第一行抛出异常:

@ServiceActivator(inputChannel = "producerChannel")
public MessageHandler kafkaMessageHandler() {
    KafkaProducerMessageHandler<String, String> handler =
        new KafkaProducerMessageHandler<>(kafkaTemplate());
    handler.setMessageKeyExpression(new LiteralExpression("kafka-integration"));

    return handler;
}

我的pom.xml是:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.apache.kafka</groupId>
        <artifactId>kafka-clients</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-integration</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.integration</groupId>
        <artifactId>spring-integration-kafka</artifactId>
        <version>2.3.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.kafka</groupId>
        <artifactId>spring-kafka</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

我错过了什么?

java spring apache-kafka spring-integration spring-kafka
1个回答
1
投票

compatibility matrix on the Spring for Apache Kafka project page

Spring Integration Kafka 2.3.x需要spring-kafka 1.3.x版。

Boot 1.5.x默认提取1.1.x。

<version>1.3.2.RELEASE</version>添加到spring-kafka依赖项中。

© www.soinside.com 2019 - 2024. All rights reserved.