赞
踩
在Spring boot项目中,如果同时依赖了spring-cloud-starter-stream-rabbit
和spring-boot-start-actuator
两个包,启动时可能会出现StreamBridge组件找不到的问题。如下:
*************************** APPLICATION FAILED TO START *************************** Description: Field bridge in com.venustech.electric.iops.alert.collector.job.writer.AnchorMapToStreamItemWriterBuilder required a bean of type 'org.springframework.cloud.stream.function.StreamBridge' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'org.springframework.cloud.stream.function.StreamBridge' in your configuration.
如果现象类似,着急的同学可以直接看解决方案。
案发之前,这个服务是正常运行的,只是没有启用actuator。因此,又尝试将spring-boot-start-actuator
依赖去除。果然就恢复正常了。可以断定是actuator与rabbit的包存在冲突。
一般遇到这种情况,首先是检查版本号是否冲突,根据Spring官网的说明,版本号一致的情况下,理论上不会有这种情况,如果有那就是BUG。
案发现场的环境是
Spring Boot 2.7.13
和Spring Cloud 2021.0.8
,这个两个版本号是符合官方要求的。那无疑是点背撞上BUG了。
之前也有过同时使用rabbit和actuator的成功案例,从未发生过类似事件。因此,尝试了从多种角度去解决问题,包括但不限于:
spring-cloud-starter-stream-rabbit
依赖的包都手动再依赖一次;@EnableRabbit
的配置开关;以上这些方式在本案中都没有办法解决问题。最终,参考了CSDN上的一篇文章找到了答案:《记录一次streamBridge could not be found的问题》
这里也要给该文章的作者点个赞,他解决问题的思路非常清晰。
这个问题根本原因是SimpleFunctionRegistry
类由于在运行时对应的开关配置没有开启,导致没有被正确加载。
启用打开spring.functional.enabled
配置。
spring.functional.enabled=true
spring:
functional:
enabled: true
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。