标签:
1:如果static方法 public static UserService creatUserServiceimpl() { return new UserServiceimpl(); } <bean id="userservice" class="com.bj.jiekou.UserServiceFactory" factory-method="creatUserServiceimpl"></bean> 2:非静态方法创建实例 public UserService creatUserServiceimpl() { return new UserServiceimpl(); } <bean id="factory" class="com.bj.jiekou.UserServiceFactory"></bean> <bean id="userFactory" factory-bean="factory" factory-method="creatUserServiceimpl"></bean> ApplicationContext accContext = new ClassPathXmlApplicationContext("com/bj/jiekou/beans.xml"); UserService bean2 = (UserService)accContext.getBean("userFactory"); bean2.saveUser();
标签:
原文地址:http://www.cnblogs.com/baijin05/p/5053053.html