mirror of
https://gitee.com/dromara/cubic.git
synced 2024-12-03 12:48:41 +08:00
修复动态参数问题
This commit is contained in:
parent
810f2aaf65
commit
38d1af69ad
@ -11,6 +11,7 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -28,6 +29,8 @@ public class CubicConfInitalizer {
|
||||
|
||||
private final static String SYSTEM_CONFIG_PATH = "cubic_config";
|
||||
private final static String DEFAULT_CONFIG_FILE_NAME = "/config/agent.config";
|
||||
private static final String ENV_KEY_PREFIX = "cubic.";
|
||||
|
||||
private static boolean IS_INIT_COMPLETED = false;
|
||||
|
||||
public static void initConfig() {
|
||||
@ -39,6 +42,12 @@ public class CubicConfInitalizer {
|
||||
logger.error("Failed to read the config file, agent will is going to run in default config.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
overrideConfigBySystemProp();
|
||||
} catch (Exception e) {
|
||||
logger.error( "Failed to read the system properties.",e);
|
||||
}
|
||||
|
||||
IS_INIT_COMPLETED = true;
|
||||
|
||||
if(StringUtils.isEmpty(AgentConfig.Agent.INSTANCE_UUID)){
|
||||
@ -66,4 +75,20 @@ public class CubicConfInitalizer {
|
||||
throw new CubicConfigNotFoundException("Failed to load agent.config");
|
||||
|
||||
}
|
||||
|
||||
private static void overrideConfigBySystemProp() throws IllegalAccessException {
|
||||
Properties properties = new Properties();
|
||||
Properties systemProperties = System.getProperties();
|
||||
for (final Map.Entry<Object, Object> prop : systemProperties.entrySet()) {
|
||||
String key = prop.getKey().toString();
|
||||
if (key.startsWith(ENV_KEY_PREFIX)) {
|
||||
String realKey = key.substring(ENV_KEY_PREFIX.length());
|
||||
properties.put(realKey, prop.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (!properties.isEmpty()) {
|
||||
CubicConfigConvert.initialize(properties, AgentConfig.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,10 @@ spring:
|
||||
password: admin
|
||||
profiles:
|
||||
active: dev
|
||||
redis:
|
||||
lettuce:
|
||||
pool:
|
||||
max-active:
|
||||
server:
|
||||
port: 6081
|
||||
tomcat:
|
||||
@ -23,6 +27,7 @@ management:
|
||||
web:
|
||||
base-path: /
|
||||
|
||||
|
||||
log:
|
||||
level: info
|
||||
path: /tmp/logs
|
||||
|
Loading…
Reference in New Issue
Block a user