覆蓋 Spring Boot 依賴項

在 Spring Boot 應用程式中使用 Spring for Apache Kafka 時,Apache Kafka 的依賴版本由 Spring Boot 的依賴管理確定。如果您希望使用不同版本的 kafka-clientskafka-streams,並且使用嵌入式 Kafka 代理進行測試,您需要覆蓋 Spring Boot 依賴管理使用的版本;設定 kafka.version 屬性。

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 屬性。

  • Maven

  • Gradle

<properties>
    <kafka.version>4.0.0</kafka.version>
    <spring-kafka.version>4.0.0</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.0'

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 代理時,才需要測試範圍的依賴項。

© . This site is unofficial and not affiliated with VMware.