这个版本仍在开发中,目前尚未被认为是稳定的。要使用最新稳定版本,请使用 Spring for Apache Kafka 4.0.4spring-doc.cadn.net.cn

覆盖 Spring Boot 依赖项

当在 Spring Boot 应用程序中使用 Spring for Apache Kafka 时,Apache Kafka 依赖项的版本由 Spring Boot 的依赖管理确定。 如果你希望使用不同版本的 kafka-clientskafka-streams,并且使用嵌入式的 kafka broker 进行测试,就需要覆盖 Spring Boot 依赖管理所使用的版本;设置 kafka.version 属性。spring-doc.cadn.net.cn

Both Spring Boot 3.5.x 和 3.4.x 使用 kafka-clients 版本 3.8.x,如果用户需要使用 3.9.x 客户端,他们需要按照以下方法手动升级它。

或者,要使用与受支持的 Spring Boot 版本兼容的不同 Spring for Apache Kafka 版本,请设置 spring-kafka.version 属性。spring-doc.cadn.net.cn

<properties>
    <kafka.version>4.0.0</kafka.version>
    <spring-kafka.version>4.0.5-SNAPSHOT</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'] = '4.0.5-SNAPSHOT'

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 broker时才需要。spring-doc.cadn.net.cn