解决springboot3不兼容rocketmq问题

今天学习springboot整合rocketmq时,使用@Autowired注解自动装配RocketMQTemplate失败

报错如下

Description:

Field rocketMQTemplate in com.example.demo17springbootmq.service.rocketmq.MessageServiceRocketmqImpl required a bean of type 'org.apache.rocketmq.spring.core.RocketMQTemplate' 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.apache.rocketmq.spring.core.RocketMQTemplate' in your configuration.

提示RocketMQTemplate无法被找到

(当前日期为2023.04.21)最终发现是版本不兼容问题,rocketmq最新的版本(5.1)目前还不兼容springboot3,因为springboot3修改了一些相关内容

最终在github中rocketmq的官方项目中找到一篇issue解决了这个问题

Fix: #539 Support SpringBoot 3.x.

Springboot-3.0 has abandoned spring.factories automatic assembly, it's replace by /resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports, add this file for compatibility.

翻译如下

修复: #539 支持SpringBoot 3.x。

Springboot-3.0已经放弃了spring.plants自动装配,它被/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.import所取代,添加这个文件是为了兼容。

解决方法

在resources目录中创建META-INF文件夹,

在这个文件夹中创建spring文件夹,

在spring文件夹中创建一个名为org.springframework.boot.autoconfigure.AutoConfiguration.import的文件

org.springframework.boot.autoconfigure.AutoConfiguration.import

即可成功启动

原issue链接:https://github.com/apache/rocketmq-spring/pull/541 

猜你喜欢

转载自blog.csdn.net/m0_54250110/article/details/130282674