fix read property file error

This commit is contained in:
qingliang.ql 2019-02-25 12:16:21 +08:00
parent eb87625083
commit 999a244eb3

View File

@ -17,11 +17,11 @@
package com.alibaba.nacos.core.utils; package com.alibaba.nacos.core.utils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.net.URI; import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -31,18 +31,21 @@ import java.util.Properties;
*/ */
public class PropertyUtil { public class PropertyUtil {
private static Properties properties = new Properties(); private static Properties properties = new Properties();
private static final Logger log = LoggerFactory.getLogger(PropertyUtil.class);
static { static {
try { try {
URL configURL = PropertyUtil.class InputStream inputStream = null;
.getResource("/application.properties"); String baseDir = System.getProperty("nacos.home");
if (configURL != null) { if (!StringUtils.isBlank(baseDir)) {
URI configURI = configURL.toURI(); inputStream = new FileInputStream(baseDir + "/conf/application.properties");
File file = new File(configURI); } else {
properties = new Properties(); inputStream = PropertyUtil.class
properties.load(new FileInputStream(file)); .getResourceAsStream("/application.properties");
} }
properties.load(inputStream);
} catch (Exception e) { } catch (Exception e) {
log.error("read property file error:" + e);
} }
} }