附录 A:覆盖 Spring Boot 依赖项
在 Spring Boot 应用程序中使用 Spring for Apache Kafka 时,Apache Kafka 依赖项版本由 Spring Boot 的依赖项管理确定。
如果您希望使用不同版本的 or ,并使用嵌入式 kafka 代理进行测试,则需要覆盖 Spring Boot 依赖项管理使用的版本,并为 Apache Kafka 添加两个工件。kafka-clients
kafka-streams
test
Maven 系列
<properties>
<kafka.version>3.1.0</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>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<classifier>test</classifier>
<scope>test</scope>
<version>${kafka.version}</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.13</artifactId>
<classifier>test</classifier>
<scope>test</scope>
<version>${kafka.version}</version>
</dependency>
Gradle
ext['kafka.version'] = '2.8.1'
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') {
// needed if downgrading to Apache Kafka 2.8.1
exclude group: 'org.apache.zookeeper', module: 'zookeeper'
}
testImplementation "org.apache.kafka:kafka-clients:${kafka.version}:test"
testImplementation "org.apache.kafka:kafka_2.13:${kafka.version}:test"
}
仅当在测试中使用嵌入式 Kafka 代理时,才需要测试范围依赖项。