factory-bean:用于实例化工厂类
factory-method:用于调用工厂类方法。
对于静态方法:
public class MyBeanFactory {
/**
* 创建实例
***/
public static UserService createService(){
return new UserServiceImpl();
}
}
UserServiceimpl类中的实现:
public class UserServiceImpl implements UserService {
public void addUser() {
System.out.println("b_static_factory_ico add user");
// TODO Auto-generated method stub
}
}
bean:
<bean id="userServiceId" class="com.itheima.c_inject.b_static_factory.MyBeanFactory" factory-method="createService"></bean>
对于非静态方法的注入:
public class MyBeanFactory {
/**
* 创建实例
***/
public UserService createService(){
return new UserServiceImpl();
}
}
<bean id="userServiceId" factory-bean="MyBeanFactoryId" factory-method="createService"></bean>
<!-- 实例化工厂对象 -->
<bean id="MyBeanFactoryId" class="com.itheima.c_inject.c_factory.MyBeanFactory"></bean>
</beans>
factory-bean:用于实例化工厂类
factory-method:用于调用工厂类方法。