spring the factory class

package factory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class Factory {
    public static Map<String,Object> bean = new HashMap<String, Object>();//存放配置文件对象
    public static Properties properties;
    static{
        properties = new Properties();
        InputStream is = Factory.class .getClassLoader () the getResourceAsStream ( "pro.properties");. // class loader profile acquired 
        the try { 
            Properties.load (IS); // load the resource file 
            the Enumeration properties.keys Keys = (); // get all key 
            the while (keys.hasMoreElements ()) { // condition 

                String key = keys.nextElement () toString ();. // next a value 
                String value = Properties.getProperty (key); // a key value 
                Class cls the Class.forName = (value); // loaded into memory 
                Object cls.newInstance O = (); // Create Object
                bean.put(key, o);
            }
            }catch (Exception e) {
                e.printStackTrace();
            }
        System.out.println(bean);
    }
    public static Object getPath(String path){
        return bean.get(path);//由键取值
    }
}

Please feel free to leave a message or have problems raised guidance, thank you ah ~

Guess you like

Origin www.cnblogs.com/pikajiu/p/11335061.html