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了。

猜你喜欢

转载自www.cnblogs.com/yidiandhappy/p/9009477.html
今日推荐