private static Map<String,Object> beanmap=new HashMap<String,Object>(); //为getbean方法获取bean准备一个容器,使用map容器,因为有key static{ bundle=ResourceBundle.getBundle("bean"); Enumeration<String> keys = bundle.getKeys(); while(keys.hasMoreElements()){ String beanName=keys.nextElement(); try { Object o = Class.forName(bundle.getString(beanName)).newInstance(); beanmap.put(beanName,o); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } public static Object getbean(String beanName) throws ClassNotFoundException, IllegalAccessException, InstantiationException { // Object o = Class.forName(properties.get(beanName).toString()).newInstance(); //Object o = Class.forName(bundle.getString(beanName)).newInstance(); Object o = beanmap.get(beanName); return o;