封装RabbitMQ工具类出现required a bean of type ‘java.lang.String‘ that could not be found

封装RabbitMQ工具类过程中,报了required a bean of type 'java.lang.String' that could not be found这个问题:

封装RabbitMQ工具类出现required a bean of type ‘java.lang.String‘ that could not be found

回看代码很容易发现在参数这里出现的问题:

封装RabbitMQ工具类出现required a bean of type ‘java.lang.String‘ that could not be found

继续往下看:

封装RabbitMQ工具类出现required a bean of type ‘java.lang.String‘ that could not be found

问题已经很明白了,由于疏忽,在注册Bean的过程中,参数并没有被spring托管,导致参数不能实例化注入到方法中,通过方法创建的Bean自然在没有参数的情况下创建Bean被spring托管。因此,在创建Bean的过程中,在Bean注册过程中把参数直接传入即可。

修改后:

封装RabbitMQ工具类出现required a bean of type ‘java.lang.String‘ that could not be found

封装RabbitMQ工具类出现required a bean of type ‘java.lang.String‘ that could not be found

启动测试:

封装RabbitMQ工具类出现required a bean of type ‘java.lang.String‘ that could not be found

一切正常。