通過XML創建裝配bean 1.裝配不存在成員變數的bean <bean id="talent" class="cn.jqzhong.Spring.study.day2.LiteraryTalent"></bean> 2.裝配存在成員變數的bean 2.1.1屬性值為引用類型、引用類型列表 <bea ...
通過XML創建裝配bean
1.裝配不存在成員變數的bean
<bean id="talent" class="cn.jqzhong.Spring.study.day2.LiteraryTalent"></bean>
2.裝配存在成員變數的bean
2.1通過構造器註入
2.1.1屬性值為引用類型、引用類型列表
<bean id="people" class="cn.jqzhong.Spring.study.day2.LikeMePeople">
<constructor-arg ref="talent"></constructor-arg><constructor-arg>
<list>
<ref bean=""></ref>
<ref bean=""></ref>
</list>
</constructor-arg>
</bean>
2.1.2屬性值為字面值、字面值類型列表
<bean id="people" class="cn.jqzhong.Spring.study.day2.LikeMePeople">
<constructor-arg value="xxx"></constructor-arg>
<constructor-arg>
<list>
<value>xxx</value>
<value>xxx</value>
</list>
</constructor-arg>
</bean>
2.2通過屬性設置
2.2.1屬性值為引用類型、引用類型列表
<bean id="people" class="cn.jqzhong.Spring.study.day2.LikeMePeople">
<property name="talent" ref="talent"></property>
<property>
<list>
<ref bean=""></ref>
<ref bean=""></ref>
</list>
</property>
</bean>
2.2.2屬性值為屬性值為字面值、字面值類型列表
<bean id="people" class="cn.jqzhong.Spring.study.day2.LikeMePeople">
<property name="talent" value="xxx"></property>
<property name="otherTlent">
<list>
<value>xxx</value>
<value>xxx</value>
</list>
</property>
</bean>