一:使用Spring默认的方法;
<bean id="personService" class="com.dys.service.impl.PersonServiceBean"></bean>
二:静态工厂方法实例化bean
<bean id="personService" class="com.dys.service.factory.PersonServiceBeanFactory" factory-method="createPersonServiceBean">
package com.dys.service.factory;
import com.dys.service.impl.PersonServiceBean;
public class PersonServiceBeanFactory {
//静态工厂方法实例化
bean public static PersonServiceBean createPersonServiceBean(){
return new PersonServiceBean();
}
}
三:实例工厂方法实例化
package com.dys.service.factory;
import com.dys.service.impl.PersonServiceBean;
public class PersonServiceBeanFactory {
//静态工厂方法实例化bean
public PersonServiceBean createPersonServiceBean(){
return new PersonServiceBean();
}
}
<bean id="personServiceBeanFactory" class="com.dys.service.factory.PersonServiceBeanFactory"></bean>
<bean id="personService" factory-bean="personServiceBeanFactory" factory-method="createPersonServiceBean"></bean>
来源:https://www.cnblogs.com/dingyingsi/archive/2013/02/26/2933627.html