今天实现一个业务,需要用到队列进行数据同步,所以加入了MQ。之前一直使用SpringBoot 2.x,今天尝试了一下最新版本,就出现问题了。
Field rocketMQTemplate in tech.kunyuan.api.service.impl.RocketMqProducerServiceImpl required a bean of type 'org.apache.rocketmq.spring.core.RocketMQTemplate' that could not be found.

尝试了很多办法都没有解决,但又不想降低SpringBoot的版本。
最终在github中RocketMQ的官方项目中找到一篇issue解决了这个问题。
原因是:
Springboot-3.0已经放弃了spring.plants自动装配,它被/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.import所取代,添加这个文件是为了兼容。
添加META-INF后,写入
org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration


成功

测试发送


用RocketMQ的时候,客户端与服务器端一定要使用相同的版本。否则可能会导致重启应用后重复消费的问题。