Spring学习(一) 三种实例化bean的方式

1.使用类构造器实例化
<bean id="personService" class="com.bill.impl.PersonServiceBean">

2.使用静态工厂方法实例化
<bean id="personService2" class="com.bill.impl.PersonServiceBeanFactory" 
          factory-method="createPersonServiceBean"/>

public static PersonServiceBean createPersonServiceBean(){
		return new PersonServiceBean();//通过工厂类的静态方法创建PersonServiceBean对象
	}

3.使用实例化工厂方法实例化
先实例化工厂类PersonServiceBeanFactory,然后再通过工厂类的方法创建PersonServiceBean对象
<bean id="personServiceFactory" class="com.bill.impl.PersonServiceBeanFactory"/>
	<bean id="personService3" factory-bean="personServiceFactory" factory-method="createPersonServiceBean2"/>

public PersonServiceBean createPersonServiceBean2(){
		return new PersonServiceBean();
	}

你可能感兴趣的:(bean)