1. 使用构造方法实例化,最常用的
<bean id="myService" class="com.mooing.service.MyServiceImpl"/>
2. 使用静态工厂方法实例化
public static class MyServiceFactory {
public static MyService createBean() {
return new MyServiceImpl();
}
}
<bean id="myService1" class="com.mooing.service.MyServiceFactory" factory-method="createBean"/>
3. 使用实例工厂方法实例化
public class MyServiceFactory {
public MyService createBean2() {
return new MyServiceImpl();
}
}
<bean id="myServiceFactory" class="com.mooing.service.MyServiceFactory" />
<bean id="myService2" factory-bean="myServiceFactory" factory-method="createBean2"/>
http://blog.csdn.net/chiperfect/article/details/6645078