Solve the problem that springboot3 is not compatible with rocketmq

Today, when I was learning to integrate rocketmq with springboot, I failed to use the @Autowired annotation to automatically assemble RocketMQTemplate.

The error is reported as follows

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.

Prompt RocketMQTemplate cannot be found

(The current date is 2023.04.21) It was eventually discovered that it was a version incompatibility issue. The latest version of rocketmq (5.1) is not currently compatible with springboot3 because springboot3 has modified some related content.

Finally, I found an issue in the official project of rocketmq in github and solved this problem.

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.

Translated as follows

Fix: #539 Support SpringBoot 3.x.

Springboot-3.0 has abandoned spring.plants autowiring, which has been replaced by /resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.import. This file is added for compatibility.

Solution

Create the META-INF folder in the resources directory,

Create the spring folder in this folder,

Create a file named org.springframework.boot.autoconfigure.AutoConfiguration.import in the spring folder

org.springframework.boot.autoconfigure.AutoConfiguration.import

to start successfully

Original issue link: https://github.com/apache/rocketmq-spring/pull/541 

Guess you like

Origin blog.csdn.net/m0_54250110/article/details/130282674