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

添加spring-boot-starter-web-services后Spring Cloud RabbitMQ不自动创建队列

冲突根因

  • spring-boot-starter-web-services 会引入Servlet栈的Spring Web核心组件,将应用上下文识别为Servlet Web环境,默认触发Spring Boot Web层的初始化逻辑。
  • Spring Cloud Stream 3.x+版本的函数绑定逻辑中,BindableProxyFactory 这个核心绑定组件的注册有隐含条件:当应用处于Servlet Web环境且没有显式声明需要绑定的函数时,FunctionConfiguration 会默认跳过函数绑定相关Bean的注册,这就是你观察到BindableProxyFactory Bean不存在的直接原因。
  • 额外的冲突点:spring-boot-starter-web-services 自带的消息转换器配置优先级高于Spring Cloud Stream的默认配置,会导致无法识别函数Bean的输入输出类型,进一步阻断绑定流程。

解决方案

  1. 显式声明需要绑定的函数
    在application配置文件中添加如下配置,指定你需要绑定的函数名,多个函数用分号分隔:
spring.cloud.stream.function.definition=receiveResponse
  1. 调整应用上下文类型
    如果你的项目不需要对外提供Web服务,可以直接将应用设置为非Web类型,避免Servlet环境的影响:
spring.main.web-application-type=none
  1. 手动注册绑定组件
    如果上述配置都不生效,可以手动注入BindableProxyFactory Bean强制触发绑定:
import org.springframework.cloud.stream.function.BindableProxyFactory;
import org.springframework.cloud.stream.function.FunctionCatalog;
import org.springframework.cloud.stream.config.BindingServiceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class StreamBindingConfig {
    @Bean
    public BindableProxyFactory bindableProxyFactory(FunctionCatalog functionCatalog, BindingServiceProperties bindingServiceProperties) {
        return new BindableProxyFactory(functionCatalog, bindingServiceProperties);
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 05:24:06