第一,使用类构造器实例化:
第二,使用静态工厂方法实例化:
第三种,通过实例工厂实例化:
<bean id="personService" class="com.jack.service.impl.PersonService"></bean>
第二,使用静态工厂方法实例化:
<!--配置文件-->
<bean id="personService1" class="com.jack.service.impl.PersonServiceFactory"
factory-method="createPersonService"></bean>
//java代码
public class PersonServiceFactory {
public static PersonService createPersonService(){
return new PersonService();
}
}
第三种,通过实例工厂实例化:
<bean id="personServiceFactory" class="com.jack.service.impl.PersonServiceFactory"></bean>
<bean id="personService2" factory-bean="personServiceFactory"
factory-method="createPersonService2"></bean>
public PersonService createPersonService2(){
return new PersonService();
}