对于最新的稳定版本,请使用 Spring for Apache Kafka 3.2.1Spring中文文档

对于最新的稳定版本,请使用 Spring for Apache Kafka 3.2.1Spring中文文档

在 Spring Boot 应用程序中使用 Spring for Apache Kafka 时,Apache Kafka 依赖项版本由 Spring Boot 的依赖项管理确定。 如果您希望使用不同版本的 或 并使用嵌入式 kafka 代理进行测试,则需要覆盖 Spring Boot 依赖项管理使用的版本;设置属性。kafka-clientskafka-streamskafka.versionSpring中文文档

Spring Boot 3.0.x 和 3.1.x 的默认依赖项分别为 3.3.2 和 3.4.1。kafka-clients
Spring Boot 3.0.x 和 3.1.x 的默认依赖项分别为 3.3.2 和 3.4.1。kafka-clients

或者,若要使用具有受支持的 Spring Boot 版本的不同 Spring for Apache Kafka 版本,请设置该属性。spring-kafka.versionSpring中文文档

<properties>
    <kafka.version>3.5.1</kafka.version>
    <spring-kafka.version>3.1.6</spring-kafka.version>
</properties>

<dependency>
    <groupId>org.springframework.kafka</groupId>
    <artifactId>spring-kafka</artifactId>
</dependency>
<!-- optional - only needed when using kafka-streams -->
<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-streams</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.kafka</groupId>
    <artifactId>spring-kafka-test</artifactId>
    <scope>test</scope>
</dependency>
ext['kafka.version'] = '3.5.0'
ext['spring-kafka.version'] = '3.1.6'

dependencies {
    implementation 'org.springframework.kafka:spring-kafka'
    implementation 'org.apache.kafka:kafka-streams' // optional - only needed when using kafka-streams
    testImplementation 'org.springframework.kafka:spring-kafka-test'
}

只有在测试中使用嵌入式 Kafka 代理时,才需要测试范围依赖项。Spring中文文档