Spring Boot 3.4.0升级后出现ConverterNotFoundException异常求助
问题解决:Spring Boot 3.4.0 + Spring Cloud 2024.0.0 路由键表达式绑定异常
异常原因
Spring Cloud 2024.0.0(Leyton)对配置属性的类型绑定逻辑做了调整,原版本中自动将字符串格式的SpEL表达式转换为Expression类型的逻辑被移除或严格限制,导致直接配置的字符串无法被正确转换。
解决方案
1. 调整配置写法(推荐)
在application.properties中,用#{...}包裹SpEL表达式,让Spring容器自动解析为Expression类型:
spring.cloud.stream.rabbit.default.producer.routing-key-expression=#{'response.' + headers.get('tenant')}
如果使用YAML配置文件,写法更简洁(无需额外转义):
spring: cloud: stream: rabbit: default: producer: routing-key-expression: "'response.' + headers.get('tenant')"
2. 确保依赖版本匹配
避免混用不同版本的Spring Cloud组件,Spring Boot 3.4.0必须搭配Spring Cloud 2024.0.0(Leyton)版本的所有组件,包括spring-cloud-stream-binder-rabbit,确保依赖管理中没有旧版本残留。
3. 临时兼容方案(不推荐长期使用)
如果上述方法无效,可添加配置告知框架将属性作为字符串处理,内部自动转换为Expression:
spring.cloud.stream.rabbit.default.producer.routing-key-expression-type=string
内容的提问来源于stack exchange,提问作者benschroeder
相关产品推荐
相关产品推荐

