bean实例化三种方式
- 第一种:无参构造
-
<!--无参数构造--> <bean id="userService" class="com.hgd.spring.service.UserServiceImpl"></bean>
- 第二种:静态工厂
-
public class StaticFactory { public static UserService createUserService(){ return new UserServiceImpl(); } } <!--静态工厂--> <bean id="userService" class="com.hgd.spring.factory.StaticFactory" factory-method="createUserService"/>
- 第三种:实例工厂
-
public class InnerFactory { public UserService createUserService(){ return new UserServiceImpl(); } } <!--实例工厂--> <bean id="inner" class="com.hgd.spring.factory.InnerFactory"/> <bean id="userService" factory-bean="inner" factory-method="createUserService"/>