我们都知道,在spring的配置文件里面,可以给一个bean配置多个别名,但是我们要注意:
(1),同一个bean里面,配置的别名是可以重复的。
(2),不同的bean之间的别名是不可以重复的,如果重复的话,spring会抛出一个该别名已经别定义的异常。
<?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.niepengfei.a_helloworld.Person" scope="prototype" name="person1_1,person1_2,person1_3">
<property name="id">
<value>1</value>
</property>
<property name="name">
<value>张三</value>
</property>
<property name="password">
<value>123456</value>
</property>
</bean>
<bean id="personChild" class="com.niepengfei.a_helloworld.Person" scope="prototype" name="personChild_1,personChild_2,personChild_3">
<property name="id">
<value>1</value>
</property>
<property name="name">
<value>张三</value>
</property>
<property name="password">
<value>123456</value>
</property>
</bean>
</beans>