類初始化的時候就載入properties檔案中的屬性值
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 = "";
}