工厂方法构建Bean
创建一个工厂类
public class BuildOwner {
public static Owner build(){
return new Owner();
}
}
<bean id="owner1" class="org.sl.mgrhouse.eneities.BuildOwner" factory-method="build"></bean>
依赖注入的方法
Setter(属性)注入
<bean id="owner2" class="org.sl.mgrhouse.eneities.Owner" >
<property name="name" value="李四"></property>
</bean>
构造器注入
<bean id="owner4" class="org.sl.mgrhouse.eneities.Owner" >
<constructor-arg name="name" value="麻子"/>
<constructor-arg name="phone" value="123456789"/>
<constructor-arg name="sex" value="女"/>
</bean>
不同的类型使用属性注入
基本数据类型注入
<bean id="owner2" class="org.sl.mgrhouse.eneities.Owner" >
<property name="name" value="李四"></property>
</bean>
引用数据类型注入
<bean id="owner4" class="org.sl.mgrhouse.eneities.Owner" >
<property name="realEstates">
<list>
<ref bean="re1"/>
<ref bean="re2"/>
</list>
</property>
</bean>
<bean id="re1" class="org.sl.mgrhouse.eneities.RealEstate">
<property name="reName" value="住房"/>
</bean>
<bean id="re2" class="org.sl.mgrhouse.eneities.RealEstate">
<property name="reName" value="轿车"/>
</bean>
数组类型注入
<bean id="owner2" class="org.sl.mgrhouse.eneities.Owner" >
<property name="array">
<array>
<value>"这是数组"</value>
</array>
</property>
</bean>
set集合注入
<bean id="owner2" class="org.sl.mgrhouse.eneities.Owner" >
<property name="set">
<set><value>"这是set"</value></set>
</property>
</bean>
Map集合注入
<bean id="owner2" class="org.sl.mgrhouse.eneities.Owner" >
<property name="map">
<map>
<entry key="key" value="value"/>
<entry key="key1" value="value1"/>
</map>
</property>
</bean>
property类型注入
<bean id="owner2" class="org.sl.mgrhouse.eneities.Owner" >
<property name="properties">
<props>
<prop key="prope">prope1s</prop>
</props>
</property>
</bean>