spring学习笔记二

1.使用类构造器实例化(默认无参数)
<bean id=“bean名称" class="bean完整类名"/>
<bean id="personDaoImpl" class="cn.yue.daoImpl.PersonDaoImpl"></bean>


工厂模式:简单工厂模式 工厂方法模式 抽像工厂模式


2.使用静态工厂方法实例化(简单工厂模式)
<bean id="bean名称"  class="bean完整类名"    factory-method="方法名" />
<bean id="factory" class="cn.yue.factory.DaoFactory" factory-method="createPersonDaoImpl"></bean>
public class DaoFactory {
public static PersonDao createPersonDaoImpl()
{
return new PersonDaoImpl();
}
}
3.使用实例工厂方法实例化(工厂方法模式):
 <bean id=“bean名称" class="完整类名"/>
 <bean id="personService" factory-bean=“bean名称"   factory-method="createPersonService" />
public class PersonServiceFactory {
public personServiceFactory()
{               
}
       public  PersonService createPersonService(){
                     return new PersonServiceImpl();
       }
}
posted @ 2012-09-07 09:47  retacn_yue  阅读(94)  评论(0编辑  收藏  举报