You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Pulsar集成Spring Cloud Stream遇依赖缺失问题如何解决?

问题描述

搭建集成Apache Pulsar的Spring Boot应用,通过Spring Cloud Stream实现消息流处理时出现构建错误:

auth-service:main: Could not find org.springframework.pulsar:spring-pulsar-spring-cloud-stream-binder:.
Required by:
    root project :

当前build.gradle.kts配置片段:

plugins {
    kotlin("jvm") version "2.1.20"
    kotlin("plugin.spring") version "2.1.20"
    id("org.springframework.boot") version "3.4.5"
    id("io.spring.dependency-management") version "1.1.7"
    id("com.google.protobuf") version "0.9.5"
    kotlin("plugin.jpa") version "1.9.25"
}

// Other configuration...

dependencies {
    // Other dependencies...
    
    // Pulsar dependencies causing the issue
    implementation("org.springframework.pulsar:spring-pulsar-spring-boot-starter:0.2.0")
    implementation("org.springframework.boot:spring-boot-starter-pulsar-reactive")
    implementation("org.springframework.pulsar:spring-pulsar-spring-cloud-stream-binder")
    
    // Other dependencies...
}

extra["springCloudVersion"] = "2024.0.1"
extra["springGrpcVersion"] = "0.8.0"

dependencyManagement {
    imports {
        mavenBom("org.springframework.grpc:spring-grpc-dependencies:${property("springGrpcVersion")}")
        mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
    }
}

已尝试操作:

  • 按官方文档要求添加依赖
  • 在Maven Central中查找该构件
  • 在Spring文档中查找版本信息

环境信息:

  • Kotlin: 2.1.20
  • Spring Boot: 3.4.5
  • Spring Cloud: 2024.0.1
  • Spring Pulsar: 0.2.0

问题:如何正确配置Spring Cloud Stream的Spring Pulsar binder?该依赖是否需要指定特定版本,或有其他集成Pulsar与Spring Cloud Stream的替代方案?

补充:Kafka binder可正常工作。


解决方案

1. 修正依赖坐标

你使用的Pulsar binder依赖坐标已过时,当前Spring Cloud Stream的Pulsar binder归属org.springframework.cloud组,正确的依赖坐标为:

implementation("org.springframework.cloud:spring-cloud-stream-binder-pulsar")

旧的org.springframework.pulsar:spring-pulsar-spring-cloud-stream-binder是早期版本的坐标,现已不再维护,Maven仓库中无对应构件。

2. 移除冲突/过时依赖

  • 删除手动指定版本的spring-pulsar-spring-boot-starter:0.2.0:该版本过低,与Spring Boot 3.4.5不兼容,且Spring Cloud Stream Pulsar binder会自动引入适配版本的Spring Pulsar依赖。
  • 若仍需使用反应式Pulsar功能,保留spring-boot-starter-pulsar-reactive即可,它会通过Spring Boot的依赖管理自动匹配正确版本。

3. 调整后的依赖配置片段

dependencies {
    // Other dependencies...
    
    // 正确的Pulsar Stream Binder依赖
    implementation("org.springframework.cloud:spring-cloud-stream-binder-pulsar")
    // 反应式Pulsar Starter(按需保留)
    implementation("org.springframework.boot:spring-boot-starter-pulsar-reactive")
    
    // Other dependencies...
}

4. 依赖版本管理说明

你已引入Spring Cloud的BOM(spring-cloud-dependencies:2024.0.1),该BOM会自动管理Spring Cloud Stream Pulsar binder及相关依赖的版本,无需手动指定版本号,避免版本冲突。

替代方案(若上述配置仍有问题)

如果暂时无法使用官方的Spring Cloud Stream Pulsar binder,可直接使用Spring Pulsar原生API实现消息收发,但会失去Spring Cloud Stream的统一消息模型优势:

  • 引入适配版本的Spring Pulsar依赖:implementation("org.springframework.pulsar:spring-pulsar-spring-boot-starter")(版本由Spring Boot或Spring Cloud BOM管理)
  • 通过PulsarTemplate、PulsarListener等原生组件实现消息生产与消费

内容的提问来源于stack exchange,提问作者OmniCoder77

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 02:27:05