标签:log color context service gtest bean new employee val
Spring能够在applicationContext.xml中通过配置bean完成实例化对象,设置属性等。
1.配置bean
<bean id="dao" class="springTest.DaoImpl">
</bean>
实例化对象,相当于以下代码:
DaoImpl dao=new DaoImpl();
2.配置属性property
<bean id="dao" class="springTest.DaoImpl">
<property name="employee" value="lin"></property>
</bean>
设置属性,也就是setter,相当于以下代码:
DaoImpl dao=new DaoImpl();
dao.setEmployee=lin;
3.配置对象属性property
<bean id="dao" class="springTest.DaoImpl"></bean>
<bean id="serviceImpl" class="springTest.ServiceImpl">
<property name="dao" ref="dao"></property>
</bean>
设置对象属性,相当于以下代码:
DaoImpl dao=new DaoImpl();
ServiceImpl serviceImpl=new ServiceImpl();
serviceImpl.setDao=dao;
标签:log color context service gtest bean new employee val
原文地址:http://www.cnblogs.com/expiator/p/6824223.html