提供采用绝对路径来读取配置文件

main
LAPTOP-S9HJSOEB\昊天 2 years ago
parent 1301e4a3e6
commit 163e3e738c

@ -12,6 +12,7 @@ import com.leaper.pm2java.websocket.WebSocket;
import com.sun.management.OperatingSystemMXBean; import com.sun.management.OperatingSystemMXBean;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -132,10 +133,12 @@ public class Pm2JavaServiceImpl implements Pm2JavaService {
return list; return list;
} }
@Value("${appDire}")
private String appDir;
@Override @Override
public List<AppServerInfo> search() { public List<AppServerInfo> search() {
List<AppServerInfo> appServerInfos = new ArrayList<>(); List<AppServerInfo> appServerInfos = new ArrayList<>();
List<AppServerEntity> appServerEntities = FileUtil.readFile(); List<AppServerEntity> appServerEntities = FileUtil.readFile(appDir);
for (AppServerEntity appServerEntity : appServerEntities) { for (AppServerEntity appServerEntity : appServerEntities) {
AppServerInfo appServerInfo = new AppServerInfo(); AppServerInfo appServerInfo = new AppServerInfo();
appServerInfo.setName(appServerEntity.getName()); appServerInfo.setName(appServerEntity.getName());

@ -3,6 +3,7 @@ package com.leaper.pm2java.util;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.leaper.pm2java.entity.AppServerEntity; import com.leaper.pm2java.entity.AppServerEntity;
import com.leaper.pm2java.service.impl.Pm2JavaServiceImpl; import com.leaper.pm2java.service.impl.Pm2JavaServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.File; import java.io.File;
@ -18,6 +19,7 @@ public class FileUtil {
static String confPath = "/appConf/"; static String confPath = "/appConf/";
static String appSuffix = ".appConf"; static String appSuffix = ".appConf";
//持久化记录为文件 //持久化记录为文件
static public boolean saveFile(AppServerEntity appConfigEntity) { static public boolean saveFile(AppServerEntity appConfigEntity) {
appConfigEntity.setType(2); appConfigEntity.setType(2);
@ -61,9 +63,14 @@ public class FileUtil {
} }
//持久化记录为文件 //持久化记录为文件
static public List<AppServerEntity> readFile() { static public List<AppServerEntity> readFile( String appDir) {
String currentFolder = System.getProperty("user.dir"); String currentFolder;
if( appDir != null && appDir.length() > 0){
currentFolder = appDir;
}else {
currentFolder = System.getProperty("user.dir");
}
File folder = new File(currentFolder + confPath); File folder = new File(currentFolder + confPath);
File[] files = folder.listFiles(); File[] files = folder.listFiles();
List<AppServerEntity> list = new ArrayList<>(); List<AppServerEntity> list = new ArrayList<>();

@ -12,3 +12,6 @@ server:
logging: logging:
config: classpath:logback-spring.xml config: classpath:logback-spring.xml
appDire: D:\hzleaper_auto_install\pm2_java\

Loading…
Cancel
Save