Spring Cloud Strem - Swagger: A default binder has been requested, but there is no binder available

文章讲述了在集成SpringCloudStream3.2.6版本时遇到的默认binder缺失错误,以及与RocketMQ连接问题。作者通过源码跟踪发现错误可能源于Swagger的InMemorySwaggerResourcesProvider,因为它被SpringCloud当作Function处理。为解决问题,建议在BeanFactoryAwareFunctionRegistry加载前,在functionProperties中排除此Provider以防止寻找binder。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述

集成Spring Cloud Strem-3.2.6 时出现如下错误
A default binder has been requested, but there is no binder available

使用RocketMQ但是没有设置自动配置时,还是会频繁报错 未连接MQ


问题分析

1. 问题定位

一直以为是因为配置了默认binder,导致一直连接服务器。自己定义了一个默认的空白binder,但是binder的消息处理器会一直收到消息,频率和未配置时一样,消息内容是 /v2/api-docs 相关的,怀疑是Swagger的问题
自定义binder

2. 源码跟踪

项目继承了swagger,跟踪源码和日志发现创建了一个 "inMemorySwaggerResourcesProvider-out-0"的绑定,这个和 InMemorySwaggerResourcesProvider 有关
跟踪代码发现在类 org.springframework.cloud.function.context.catalog.BeanFactoryAwareFunctionRegistry 中,Spring Cloud会扫描项目中的函数接口 Function、Supplier等来寻找binder,InMemorySwaggerResourcesProvider 正好继承自Supplier,然后初始化了一个inMemorySwaggerResourcesProvider-out-0

源码截图
要解决这个就要排除这个Provider或者让它不去找binder

解决方法

该方法中有一个 函数合规性校验,从这里入手
在这里插入图片描述
isFunctionDefinitionEligible()
在这里插入图片描述
FunctionProperties, 其中是预置了一些系统需要跳过的function名称
在这里插入图片描述

BeanFactoryAwareFunctionRegistry加载前,将 functionProperties中添加会误扫描的 “inMemorySwaggerResourcesProvider”
在这里插入图片描述


结束

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值