Pārlūkot izejas kodu

修改自动配置服务器名称

郭志波 6 gadi atpakaļ
vecāks
revīzija
b32e18ffcc

+ 2 - 0
README.md

@@ -15,6 +15,8 @@ git clone http://www.leanwo.com:3000/ShangHaiLeanwo/ServerManagement.git
 ## 默认配置
 * 打开resources/Application.yml,修改属性server.port可以修改启动的端口号。
 ```
+* 打开resources/Application.yml,修改属性server.autoConfig可以修改启动的配置,部署到服务器时将autoConfig改为true,resources/applicationContext.xml,不需要添加任何服务器,系统自动添加同目录下的所有服务器,所有服务器中必须有run.bat和stop.bat,否则系统不会添加该服务器。
+```
 server:
   port: 88
 ```

+ 33 - 1
src/main/java/com/leanwo/management/util/FileUtil.java

@@ -1,7 +1,9 @@
 package com.leanwo.management.util;
 
+import java.io.BufferedReader;
 import java.io.Closeable;
 import java.io.File;
+import java.io.FileReader;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
@@ -52,7 +54,12 @@ public class FileUtil {
                if(!stopFile.exists()) {
             	   continue;
                }
-               applicationSetting.setName(f.getName());
+               String name = readFileContent(runFile);
+               name = name.replace("::", "").replace(" ", "").replace("echo", "").replace("title", "");
+               if(name == null || name.length() <= 0) {
+            	   name = f.getName();
+               }
+               applicationSetting.setName(name);
                applicationSetting.setInstallPath(filePath);
                applicationSetting.setStartBatFile("run.bat");
                applicationSetting.setStopBatFile("stop.bat");
@@ -63,4 +70,29 @@ public class FileUtil {
         return settings;
 	}
 	
+	public static String readFileContent(File file) {
+	    BufferedReader reader = null;
+	    StringBuffer sbf = new StringBuffer();
+	    try {
+	        reader = new BufferedReader(new FileReader(file));
+	        String tempStr = reader.readLine();
+	        sbf.append(tempStr);
+//	        while ((tempStr = reader.readLine()) != null) {
+//	            sbf.append(tempStr);
+//	        }
+	        reader.close();
+	        return sbf.toString();
+	    } catch (IOException e) {
+	        e.printStackTrace();
+	    } finally {
+	        if (reader != null) {
+	            try {
+	                reader.close();
+	            } catch (IOException e1) {
+	                e1.printStackTrace();
+	            }
+	        }
+	    }
+	    return sbf.toString();
+	}
 }

+ 1 - 1
src/main/resources/Application.yml

@@ -2,7 +2,7 @@
 server:
   port: 88
 #是否免配置
-  autoConfig: false
+  autoConfig: true
 spring:
   application:
     # 应用名称,会在Eureka中作为服务的id标识(serviceId)