1.使用类构造器实例化
2.使用静态工厂方法实例化
3.使用实例工厂方法实例化
<bean id="personService" class="com.spring.service.impl.PersonServiceBean"></bean>
2.使用静态工厂方法实例化
<bean id="personService" class="com.spring.service.impl.PersionServiceBeanFactory" factory-method="createPersonServiceBean"></bean>
package com.spring.service.impl;
import com.spring.service.PersonService;
public class PersionServiceBeanFactory
{
public static PersonService createPersonServiceBean()
{
return new PersonServiceBean();
}
}
3.使用实例工厂方法实例化
<bean id="personServiceFactory" class="com.spring.service.impl.PersionServiceBeanFactory"></bean>
<bean id="personService" factory-bean="personServiceFactory" factory-method="createPersonServiceBean"></bean>
package com.spring.service.impl;
import com.spring.service.PersonService;
public class PersionServiceBeanFactory
{
public PersonService createPersonServiceBean()
{
return new PersonServiceBean();
}
}