解决springboot3不兼容rocketmq问题
今天学习springboot整合rocketmq时,使用@Autowired注解自动装配RocketMQTemplate失败。
今天学习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
即可成功启动

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)