Fixed the user.properties file loading error

This commit is contained in:
walking98
2019-04-17 11:49:31 +08:00
parent 1588f70b52
commit 61b74f066d
3 changed files with 28 additions and 7 deletions

View File

@@ -11,7 +11,7 @@
<groupId>org.apache</groupId>
<artifactId>rocketmq-console-ng</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<version>1.0.1</version>
<name>rocketmq-console-ng</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@@ -147,7 +147,9 @@ public class DashboardCollectServiceImpl implements DashboardCollectService {
String dataLocationPath = rmqConfigure.getConsoleCollectData();
File file = new File(dataLocationPath + date + "_topic" + ".json");
if (!file.exists()) {
throw Throwables.propagate(new ServiceException(1, "This date have't data!"));
log.info(String.format("No dashboard data for data: %s", date);
//throw Throwables.propagate(new ServiceException(1, "This date have't data!"));
return Maps.newHashMap();
}
return jsonDataFile2map(file);
}

View File

@@ -31,6 +31,7 @@ import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.io.File;
import java.io.FileReader;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -72,19 +73,37 @@ public class UserServiceImpl implements UserService, InitializingBean {
filePath = configure.getRocketMqConsoleDataPath() + File.separator + FILE_NAME;
if (!new File(filePath).exists()) {
//Use the default path
filePath = this.getClass().getResource("/" + FILE_NAME).getPath();
InputStream inputStream = getClass().getResourceAsStream("/" + FILE_NAME);
if (inputStream == null) {
log.error(String.format("Can not found the file %s in Spring Boot jar", FILE_NAME));
System.out.printf(String.format("Can not found file %s in Spring Boot jar or %s, stop the console starting",
FILE_NAME, configure.getRocketMqConsoleDataPath()));
System.exit(1);
} else {
load(inputStream);
}
} else {
log.info(String.format("Login Users configure file is %s", filePath));
load();
watch();
}
log.info(String.format("Login Users configure file is %s", filePath));
load();
watch();
}
private void load() {
load(null);
}
private void load(InputStream inputStream) {
Properties prop = new Properties();
try {
prop.load(new FileReader(filePath));
if (inputStream == null) {
prop.load(new FileReader(filePath));
} else {
prop.load(inputStream);
}
} catch (Exception e) {
log.error("load user.properties failed", e);
throw new ServiceException(0, String.format("Failed to load loginUserInfo property file: %s", filePath));
}