附录 A:覆盖 Spring Boot 依赖项
在 Spring Boot 应用程序中使用 Spring for Apache Kafka 时,Apache Kafka 依赖版本由 Spring Boot 的依赖管理决定。如果您希望使用不同版本的kafka-clients
或kafka-streams
,并使用嵌入式 Kafka Broker 进行测试,您需要覆盖 Spring Boot 依赖管理使用的版本;将kafka.version
财产。
或者,要将不同的 Spring for Apache Kafka 版本与受支持的 Spring Boot 版本一起使用,请将spring-kafka.version
财产。
或者,要将不同的 Spring for Apache Kafka 版本与受支持的 Spring Boot 版本一起使用,请将spring-kafka.version
财产。 例如,Spring Boot 2.7.x 支持 2.9.13,默认情况下引入 2.8.x。
专家
<properties>
<kafka.version>3.6.0</kafka.version>
<spring-kafka.version>2.9.13</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>
<!-- Required for the embedded broker when using 3.6.0 or later with Boot 2.7.x -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-server-common</artifactId>
<classifier>test</classifier>
<scope>test</scope>
<version>${kafka.version}</version>
</dependency>
Gradle
ext['kafka.version'] = '3.6.0'
ext['spring-kafka.version'] = '2.9.13'
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'
// the following is required for the embedded broker when using 3.6.0 or later with Boot 2.7.x
testImplementation "org.apache.kafka:kafka-server-common:$kafka.version:test"
}
仅当您在测试中使用嵌入式 Kafka 代理时,才需要测试范围依赖项。