RocketMQ SpringBoot 3.0不兼容解决方案

最近,我们在开发公司的一个新项目时,决定采用一下新版的Spring Boot 3.0。但是,在我们整合RocketMQ的时候,却遇到了一些难题。

一切依赖都在pom.xml中写好之后,我们启动项目,报了错:


***************************
APPLICATION FAILED TO START
***************************

Description:

Field rocketMQTemplate in com.dayuwebtech.dayupay.common.rocketmq.impl.SendPayReNotifyMessageImpl 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.

 可是,其他都不变,在降级到Spring Boot 2.7.x中就是完全正常的,这是为什么呢?

仔细翻阅Spring Boot 3的文档的“迁移指南”,发现https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#auto-configuration-files

Spring Boot 2.7 introduced a new META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports file for registering auto-configurations, while maintaining backwards compatibility with registration in spring.factories. With this release, support for registering auto-configurations in spring.factories has been removed in favor of the imports file.

Spring Boot 2.7引入了一个新的META-INF/spring/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports文件,用于注册自动配置,同时保持与spring.factories注册的向后兼容性。随着此版本(Spring Boot 3)的发布,对在spring.factories中注册自动配置的支持已被删除,以支持导入文件。

也就是说,我们要在resources文件夹中,新建META-INF/spring文件夹,在里面新建一个叫org.springframework.boot.autoconfigure.AutoConfiguration.imports的文件。里面填入

org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration

如下图所示。​​​​​​​

然后,可以看到,下面就成功启功了项目啦!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员老于

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值