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