首页 > 其他 > 详细

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

时间:2017-01-03 19:22:23      阅读:238      评论:0      收藏:0      [点我收藏+]

// 配置文件名
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;
}
}

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

原文:http://www.cnblogs.com/panxuejun/p/6245587.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!