/**
* 将配置文件所有属性值读入内存,项目运行时不再读文件
*/
public static void loadProps() {
Properties prop = new Properties();
InputStream in = null;
try {
Environment environment = ApplicationContextHelper.applicationContext.getEnvironment();
in = new BufferedInputStream(new FileInputStream(environment.getProperty("conf.file.path")));
//prop.load(in);
prop.load(new InputStreamReader(in, "utf-8"));
if (prop.containsKey("workerId") && prop.containsKey("datacenterId")
&& prop.containsKey("orderIdMachineCode") && prop.containsKey("passiveBackUrl")
&& prop.containsKey("addnOpUrl")) {
workerId = Long.valueOf(prop.getProperty("workerId").trim());
datacenterId = Long.valueOf(prop.getProperty("datacenterId").trim());
orderIdMachineCode = prop.getProperty("orderIdMachineCode").trim();
passiveBackUrl = prop.getProperty("passiveBackUrl").trim();
addnOpUrl = prop.getProperty("addnOpUrl").trim();
ppcDdEncrptSm4Key = prop.getProperty("ppcDdEncrptSm4Key").trim();
logger.info("===load配置文件参数至内存===");
} else {
logger.error("===svcConfig.properties文件中workerId、datacenterId、orderIdMachineCode、"
+ "passiveBackUrl、addnOpUrl属性值部分缺失,请核查后重启项目===");
}
} catch (FileNotFoundException e) {
logger.warn("===svcConfig.properties文件不存在,请配置后重启项目===", e);
} catch (IOException ioe) {
logger.error("===读取配置文件svcConfig.properties出现IO异常===", ioe);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e1) {
logger.error("===关闭文件流出现异常===", e1);
}
}
}
}
}