1、使用构造器
<bean id="personService" class="com.spring.service.PersonService"/>
2、使用静态工厂类
<bean id="personService" class="com.spring.service.PersonServiceBeanFactory" factory-method="createPersonService">
//静态工厂类(由静态方法创建bean)
public class PersonServiceBeanFactory {
public static PersonService createPersonService(){
return new PersonService();
}
}
3、使用实例化工厂
<bean id="personServiceFactroy" class="com.spring.service.PersonServiceFactory"/>
<bean id="personService3" factory-bean="personServiceFactroy" factory-method="createPersonServiceBean"/>
//工厂类
public class PersonServiceFactory {
public PersonService createPersonServiceBean(){
return new PersonService();
}
}