跳到主要内容

覆盖 Spring Boot 依赖项

ChatGPT-4o-mini 中英对照 Override Spring Boot Dependencies

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

备注

Spring Boot 3.1.x 和 3.2.x 的默认 kafka-clients 依赖分别是 3.4.1 和 3.6.2。

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

<properties>
<kafka.version>3.5.1</kafka.version>
<spring-kafka.version>3.3.3</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>
xml

测试范围依赖项仅在您在测试中使用嵌入式 Kafka 代理时需要。