0
点赞
收藏
分享

微信扫一扫

spring 依赖注入用@Autowired报错 No unique bean of type

残北 2023-04-25 阅读 70


1,报错如下

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.springframework.amqp.rabbit.core.RabbitTemplate] is defined: expected single matching bean but found 4: [jmsTemplate1, jmsTemplate2, jmsTemplate3, jmsTemplate4]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:828)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(Autowi

2,Autowired首先根据属性名称匹配,匹配上则置入,如果没有匹配的则匹配类型相同的。这里需要将属性名称和spring配置的bean id保持一致即可



举报

相关推荐

0 条评论