From 61b74f066d4b284ee6c59b417d0e4127212e5a3c Mon Sep 17 00:00:00 2001 From: walking98 Date: Wed, 17 Apr 2019 11:49:31 +0800 Subject: [PATCH] Fixed the user.properties file loading error --- pom.xml | 2 +- .../impl/DashboardCollectServiceImpl.java | 4 ++- .../console/service/impl/UserServiceImpl.java | 29 +++++++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index c5cac4b..ab596a7 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.apache rocketmq-console-ng jar - 1.0.0 + 1.0.1 rocketmq-console-ng UTF-8 diff --git a/src/main/java/org/apache/rocketmq/console/service/impl/DashboardCollectServiceImpl.java b/src/main/java/org/apache/rocketmq/console/service/impl/DashboardCollectServiceImpl.java index d32a344..c35ea7f 100644 --- a/src/main/java/org/apache/rocketmq/console/service/impl/DashboardCollectServiceImpl.java +++ b/src/main/java/org/apache/rocketmq/console/service/impl/DashboardCollectServiceImpl.java @@ -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); } diff --git a/src/main/java/org/apache/rocketmq/console/service/impl/UserServiceImpl.java b/src/main/java/org/apache/rocketmq/console/service/impl/UserServiceImpl.java index 54ffd83..24d7010 100644 --- a/src/main/java/org/apache/rocketmq/console/service/impl/UserServiceImpl.java +++ b/src/main/java/org/apache/rocketmq/console/service/impl/UserServiceImpl.java @@ -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)); }