基本类型对象注入:
<beanid="orderService"class="cn.itcast.service.OrderServiceBean">
<constructor-arg index=“0”type=“java.lang.String” value=“xxx”/>//构造器注入
<property name=“name” value=“zhao/>//属性setter方法注入
</bean>
注入其他bean:
方式一
<beanid="orderDao" class="cn.itcast.service.OrderDaoBean"/>
<beanid="orderService"class="cn.itcast.service.OrderServiceBean">
<property name="orderDao"ref="orderDao"/>
</bean>
方式二(使用内部bean,但该bean不能被其他bean使用)
<beanid="orderService"class="cn.itcast.service.OrderServiceBean">
<property name="orderDao">
<beanclass="cn.itcast.service.OrderDaoBean"/>
</property>
</bean>
集合类型的装配
publicclass OrderServiceBean {
private Set<String> sets = newHashSet<String>();
private List<String> lists = newArrayList<String>();
private Properties properties = newProperties();
private Map<String, String> maps = newHashMap<String, String>();
....//这里省略属性的getter和setter方法
}
<beanid="order" class="cn.itcast.service.OrderServiceBean">
<property name="lists">
<list>
<value>lihuoming</value>
</list>
</property>
<property name="sets">
<set>
<value>set</value>
</set>
</property>
<property name="maps">
<map>
<entry key="lihuoming"value="28"/>
</map>
</property>
<propertyname="properties">
<props>
<propkey="12">sss</prop>
</props>
</property>
</bean>