Field amqpTemplate in * required a single bean, but 3 were found:


Field amqpTemplate in * required a single bean, but 3 were found:

Spring Boot 启动的时候报的错

使用Spring Boot1.5.8版本。

系统中使用了amqp组件,同事手写了两个RouteKey的RabbitTamplate的模板,项目中*类中@Autowired了RabbitTamplate。

然后就报了这个错,意思是找到了3个模板,不知道自动注入哪一个,建议:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

我们希望注入的是Spring Boot Auto出来的,但是我们只能使用@Qualifier(在用到的地方添加,@Qualifier(name="")指定名字)注解,因为@Primary(在定义的Bean上添加,为优先使用),但是又不可能使用原生的,所以自己定义一个。

在使用的时候使用@Qualifier指定一下自己声明的就OK了。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM