简单的写个类
1 <bean id="staticFactory" class="com.neuedu.bean.StaticFactory" factory-method="getBook">
2 <constructor-arg>
3 <value>book2</value>
4 </constructor-arg>
5 </bean>
applicationContext.xml中进行如下配置
1 package com.neuedu.bean;
2
3 import java.util.HashMap; 4 import java.util.Map; 5 6 public class InstanceFactory { 7 private static Map<String,Book> map=null; 8 static{ 9 map=new HashMap<String,Book>(); 10 map.put("book1",new Book("asdas", 20.0)); 11 map.put("book2", new Book("cxvxcv", 110.3)); 12 } 13 14 public static Book getBook(String id) { 15 return map.get(id); 16 } 17 18 }