问题

今天写 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 修改了一些相关内容

解决方法如下:

  1. 在resources目录中创建META-INF文件夹;

  2. 在这个文件夹中创建spring文件夹;

  3. 在spring文件夹中创建一个名为org.springframework.boot.autoconfigure.AutoConfiguration.import的文件
    在这里插入图片描述

  4. 其中内容为:

# RocketMQ 2.2.3 version does not adapt to SpringBoot3
org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration

大坑,检查了代码半天,都没搞懂为什么 bean 没有加载 RocketMQTemplete, 没想到被版本gank了。

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐