1 /**
2 * 加载Properties文件
3 * @param path Properties文件路径
4 * @return
5 */
6 private static Properties getClasspathProperties(String path) {
7 Assert.notNull(path);
8 InputStream in = null;
9 try {
10 File file = new File(SysUtils.class.getResource("/").getPath() + path);
11 in = new FileInputStream(file);
12
13 Properties properties = new Properties();
14 properties.load(in);
15
16 return properties;
17 } catch (IOException e) {
18 throw new SysException("无法读取资源文件:[{}],错误信息:{}", path, e.getMessage());
19 } finally {
20 if (null != in) {
21 try {
22 in.close();
23 } catch (IOException e) {
24 throw new SysException("无法读取资源文件:[{}],错误信息:{}", path, e.getMessage());
25 }
26 }
27 }
28 }
29 /**
30 * 获取Properties中key对应的value值
31 * @param properties Properties
32 * @param key 键
33 * @param defaultValue 默认值
34 * @return
35 */
36 private static String getProperty(Properties properties, String key, String defaultValue) {
37 Assert.notNull(properties);
38 Assert.hasLength(key);
39 String value = null;
40 if (properties.containsKey(key)) {
41 value = properties.getProperty(key);
42 } else {
43 LOG.info("未发现配置:" + key);
44 }
45
46 if (StringUtils.isBlank(value)) {
47 value = defaultValue;
48 }
49 LOG.debug("获取到值为{}",value);
50 return value;
51 }