Bladeren bron

[manager]fix开发和部署环境读取配置文件时路径错误

tomsun28 4 jaren geleden
bovenliggende
commit
1e5f72d2d9
1 gewijzigde bestanden met toevoegingen van 8 en 2 verwijderingen
  1. 8 2
      manager/src/main/java/com/usthe/manager/service/impl/AppServiceImpl.java

+ 8 - 2
manager/src/main/java/com/usthe/manager/service/impl/AppServiceImpl.java

@@ -123,12 +123,18 @@ public class AppServiceImpl implements AppService, CommandLineRunner {
     public void run(String... args) throws Exception {
         // 读取app定义配置加载到内存中 define/app/*.yml
         Yaml yaml = new Yaml();
-        String classpath = this.getClass().getClassLoader().getResource("").getPath();
+        String classpath = this.getClass().getResource(File.separator).getPath();
         String defineAppPath = classpath + File.separator + "define" + File.separator + "app";
         File directory = new File(defineAppPath);
         if (!directory.exists() || directory.listFiles() == null) {
-            throw new  IllegalArgumentException("define app directory not exist: " + defineAppPath);
+            classpath = this.getClass().getResource("").getPath();
+            defineAppPath = classpath + File.separator + "define" + File.separator + "app";
+            directory = new File(defineAppPath);
+            if (!directory.exists() || directory.listFiles() == null) {
+                throw new  IllegalArgumentException("define app directory not exist: " + defineAppPath);
+            }
         }
+        log.info("query define path {}", defineAppPath);
         for (File appFile : Objects.requireNonNull(directory.listFiles())) {
             if (appFile.exists()) {
                 try (FileInputStream fileInputStream = new FileInputStream(appFile)) {