Spring2.5.6学习笔记-实例化bean的几种方法
1. 用构造器来实例化
<bean id="exampleBean" class="examples.ExampleBean"/> <bean name="anotherExample" class="examples.ExampleBeanTwo"/>
2. 使用静态工厂方法实例化
注:createInstance必须是一个static方法
<bean id="exampleBean" class="examples.ExampleBean2" factory-method="createInstance"/>
3. 使用实例工厂方法实例化
<!-- the factory bean, which contains a method called createInstance() --> <bean id="serviceLocator" class="com.foo.DefaultServiceLocator"> <!-- inject any dependencies required by this locator bean --> </bean> <!-- the bean to be created via the factory bean 注:class属性必须为空--> <bean id="exampleBean" factory-bean="serviceLocator" factory-method="createInstance"/>