当前位置:   article > 正文

RocketMQ SpringBoot 3.0不兼容解决方案_consider defining a bean of type 'org.apache.rocke

consider defining a bean of type 'org.apache.rocketmq.spring.core.rocketmqte

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

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

  1. ***************************
  2. APPLICATION FAILED TO START
  3. ***************************
  4. Description:
  5. 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.
  6. The injection point has the following annotations:
  7. - @org.springframework.beans.factory.annotation.Autowired(required=true)
  8. Action:
  9. 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

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/434656
推荐阅读
相关标签
  

闽ICP备14008679号