Spring容器实例化Bean方法

 ̄綄美尐妖づ 提交于 2020-02-12 03:12:40
一:使用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>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!