Exception in thread "main" org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.atguigu.spring.bean.Person] is defined: expected single matching bean but found 2: person1,person2
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:312)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)
at com.atguigu.spring.bean.TestSpring.main(TestSpring.java:12)
错误原因:spring配置文件定义了相同class的bean
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="person1" class="com.atguigu.spring.bean.Person">
<property name="id" value="1"></property>
<property name="name" value="张三"></property>
</bean>
<bean id="person2" class="com.atguigu.spring.bean.Person">
<property name="id" value="2"></property>
<property name="name" value="李四"></property>
</bean>
</beans>