• 1.系统代码读取配置文件


    // 配置文件名
    private static final String CONFIG_CONTEXT_FILE_NAME = "context-zzgjs.properties";

    private static Configuration ins=null;

    private static Log log=LogFactory.getLog(Configuration.class);

    static {
    Properties datas = new Properties();
    try {
    datas.load(Configuration.class.getClassLoader().getResourceAsStream(CONFIG_CONTEXT_FILE_NAME));
    } catch (IOException e) {
    throw new PafaRuntimeException("Could not load configure file in classpath: "
    + CONFIG_CONTEXT_FILE_NAME + "!", e);
    }
    ins=new Configuration(datas);

    }

    private Configuration(Properties configure){
    super(configure);
    }

    /**
    * 得到配置属性值
    *
    * @param key 属性名称
    * @return 属性值
    */
    public static String getValue(String key) {
    String value=ins.getString(key);
    if(value==null){
    log.warn("Cofig item ["+key+"] is null");
    }
    return value;
    }

    /**
    * 得到配置属性值
    *
    * @param key 属性名称
    * @param defaultValue 默认值
    * @return 属性值
    */
    public static String getValue(String key, String defaultValue) {
    return ins.getString(key,defaultValue);
    }

    public static Map getConfig(){
    return ins.datas;
    }

    public static Configuration getInstance(){
    return ins;
    }
    }

  • 相关阅读:
    误卸载python2.4导致yum不能用后的修复
    网卡流量查看软件bmon
    DTD约束
    Schema约束
    SAX解析原理示意
    DOM解析原理示意
    XML中文乱码问题
    Web应用的目录结构
    手动+工具开发动态资源
    Tomcat服务器的下载及安装
  • 原文地址:https://www.cnblogs.com/panxuejun/p/6245587.html
Copyright © 2020-2023  润新知