赞
踩
最近,我们在开发公司的一个新项目时,决定采用一下新版的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
如下图所示。
然后,可以看到,下面就成功启功了项目啦!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。