代码拉取完成,页面将自动刷新
public class ServerConfigLoader implements ConfigLoader<HmilyServer> {
private final YamlPropertyLoader propertyLoader = new YamlPropertyLoader();
@Override
public void load(final Supplier<Context> context, final LoaderHandler<HmilyServer> handler) {
String filePath = System.getProperty("hmily.conf");
File configFile;
if (StringUtils.isBlank(filePath)) {
String dirPath = getDirGlobal();
configFile = new File(dirPath);
if (configFile.exists()) {
filePath = dirPath;
throw new ConfigException("ConfigLoader:loader config error,error file path:" + filePath);
} else {
//Mainly used for development environment。
ClassLoader loader = ConfigLoader.class.getClassLoader();
URL url = loader.getResource("hmily.yml");
if (url != null) {
filePath = url.getFile();
configFile = new File(filePath);
} else {
throw new ConfigException("ConfigLoader:loader config error,error file path:" + filePath);
}
}
} else {
configFile = new File(filePath);
if (!configFile.exists()) {
throw new ConfigException("ConfigLoader:loader config error,error file path:" + filePath);
}
}
try (FileInputStream inputStream = new FileInputStream(configFile)) {
List<PropertyKeySource<?>> propertyKeySources = propertyLoader.load(filePath, inputStream);
OriginalConfigLoader original = new OriginalConfigLoader();
againLoad(() -> context.get().with(propertyKeySources, original), handler, HmilyServer.class);
} catch (IOException e) {
throw new ConfigException("ConfigLoader:loader config error,file path:" + filePath);
}
}
/**
* Get the current project path.
*
* @return Current project path
*/
private String getDirGlobal() {
String userDir = System.getProperty("user.dir");
String fileName = "hmily.yml";
return String.join(String.valueOf(File.separatorChar), userDir, fileName);
}
}