/**
* 加载Properties文件
* @param path Properties文件路径
* @return
*/
private static Properties getClasspathProperties(String path) {
Assert.notNull(path);
InputStream in = null;
try {
File file = new File(SysUtils.class.getResource("/").getPath() + path);
in = new FileInputStream(file); Properties properties = new Properties();
properties.load(in); return properties;
} catch (IOException e) {
throw new SysException("无法读取资源文件:[{}],错误信息:{}", path, e.getMessage());
} finally {
if (null != in) {
try {
in.close();
} catch (IOException e) {
throw new SysException("无法读取资源文件:[{}],错误信息:{}", path, e.getMessage());
}
}
}
}
/**
* 获取Properties中key对应的value值
* @param properties Properties
* @param key 键
* @param defaultValue 默认值
* @return
*/
private static String getProperty(Properties properties, String key, String defaultValue) {
Assert.notNull(properties);
Assert.hasLength(key);
String value = null;
if (properties.containsKey(key)) {
value = properties.getProperty(key);
} else {
LOG.info("未发现配置:" + key);
} if (StringUtils.isBlank(value)) {
value = defaultValue;
}
LOG.debug("获取到值为{}",value);
return value;
}