NoUniqueBeanDefinitionException

  Exception in thread "main" org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.wangyang.demo.Person] is defined: expected single matching bean but found 2: person,personTwo
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:312)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)
at com.wangyang.demo.TestBySpring.main(TestBySpring.java:16)

 

  NoUniqueBeanDefinitionException:没有一个唯一的bean被找到;

Person person = context.getBean(Person.class);

使用Person.class,applicationContext中存在两个Peson类
posted @ 2020-03-01 21:23  荒岛°  阅读(583)  评论(0编辑  收藏  举报