RocketMQ 启动出现 RocketMQTemplate 未注入 Bean
·
问题
今天写 RocketMQ 消息队列代码时,启动 SpringBoot 突然出现报错,报错内容如下:
Description:
Parameter 0 of constructor in com.nageoffer.shortlink.project.mq.producer.ShortLinkStatsSaveProducer required a bean of type 'org.apache.rocketmq.spring.core.RocketMQTemplate' that could not be found.
Action:
Consider defining a bean of type 'org.apache.rocketmq.spring.core.RocketMQTemplate' in your configuration.
Disconnected from the target VM, address: '127.0.0.1:5144', transport: 'socket'
Process finished with exit code 1
查看了各博客的内容,终于发现了问题所在,特此记录!!!
解决方法
这个问题是因为 RocketMQ 最新的版本目前还不兼容 springboot3,因为 springboot3 修改了一些相关内容
解决方法如下:
-
在resources目录中创建META-INF文件夹;
-
在这个文件夹中创建spring文件夹;
-
在spring文件夹中创建一个名为org.springframework.boot.autoconfigure.AutoConfiguration.import的文件

-
其中内容为:
# RocketMQ 2.2.3 version does not adapt to SpringBoot3
org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration
大坑,检查了代码半天,都没搞懂为什么 bean 没有加载 RocketMQTemplete, 没想到被版本gank了。
更多推荐
所有评论(0)