码迷,mamicode.com
首页 > 其他好文 > 详细

类初始化的时候就加载properties文件中的属性值

时间:2015-02-28 14:39:08      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:properties加载 static

private static final String RULESUBMITSERVLETURL;
private static final String CALLSUBMITSERVLETURL;
static {
Properties props = new Properties();
String fileName = "sunshineserver.properties";
InputStream in = RuleDealJob.class.getClassLoader()
.getResourceAsStream(fileName);
if (in != null) {
try {
props.load(in);
RULESUBMITSERVLETURL = props.getProperty("sunshine.url")
+ props.getProperty("sunshine.ruleSubmit");
CALLSUBMITSERVLETURL = props.getProperty("sunshine.url")
+ props.getProperty("sunshine.callBackSubmit");
} catch (IOException e) {
throw new RuntimeException(
"读取接口工程地址文件失败,请确认classpath下存在intfserver.properties,"
+ e.getMessage(), e);
}finally{
if(in!=null){
try {
in.close();
} catch (IOException e) {
}
}
}
} else {
RULESUBMITSERVLETURL = "";
CALLSUBMITSERVLETURL = "";
}

类初始化的时候就加载properties文件中的属性值

标签:properties加载 static

原文地址:http://blog.csdn.net/wangyonglin1123/article/details/43984943

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!