Skip to content

Commit

Permalink
add: 添加配置文件可以指定自己的文件名和路径的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
yangfuhai committed Jan 23, 2022
1 parent 8b74add commit cc4e2d8
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/main/java/io/jboot/app/config/JbootConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,40 @@ private void init() {
}

String pathName = getConfigValue(null, "jboot_properties_path");
if (pathName == null || pathName.trim().length() == 0) {
mainProperties = new JbootProp(fileName + ".properties").getProperties();
}
//指定路径的场景
else {
mainProperties = new JbootProp(new File(pathName, fileName + ".properties")).getProperties();
}
mainProperties = getProperties(pathName, fileName + ".properties");


String mode = getConfigValue("jboot.app.mode");
if (JbootConfigKit.isNotBlank(mode)) {
//开始加载 mode properties
//并全部添加覆盖掉掉 main properties

String modePropertiesName = fileName + "-" + mode + ".properties";
mainProperties.putAll(new JbootProp(modePropertiesName).getProperties());
Properties modeProperties = getProperties(pathName, modePropertiesName);

mainProperties.putAll(modeProperties);
}


Properties externalProperties = JbootConfigKit.readExternalProperties(fileName);
if (externalProperties != null && !externalProperties.isEmpty()) {
mainProperties.putAll(externalProperties);
}


NacosConfigManager.me().init(this);
ApolloConfigManager.me().init(this);
}


private Properties getProperties(String pathName, String name) {
if (pathName != null && pathName.trim().length() > 0) {
return new JbootProp(new File(pathName, name)).getProperties();
} else {
return new JbootProp(name).getProperties();
}
}

public JbootConfigDecryptor getDecryptor() {
return decryptor;
}
Expand Down

0 comments on commit cc4e2d8

Please sign in to comment.