mirror of
https://gitee.com/dromara/cubic.git
synced 2024-12-04 13:18:09 +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.FileNotFoundException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -28,6 +29,8 @@ public class CubicConfInitalizer {
|
|||||||
|
|
||||||
private final static String SYSTEM_CONFIG_PATH = "cubic_config";
|
private final static String SYSTEM_CONFIG_PATH = "cubic_config";
|
||||||
private final static String DEFAULT_CONFIG_FILE_NAME = "/config/agent.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;
|
private static boolean IS_INIT_COMPLETED = false;
|
||||||
|
|
||||||
public static void initConfig() {
|
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);
|
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;
|
IS_INIT_COMPLETED = true;
|
||||||
|
|
||||||
if(StringUtils.isEmpty(AgentConfig.Agent.INSTANCE_UUID)){
|
if(StringUtils.isEmpty(AgentConfig.Agent.INSTANCE_UUID)){
|
||||||
@ -66,4 +75,20 @@ public class CubicConfInitalizer {
|
|||||||
throw new CubicConfigNotFoundException("Failed to load agent.config");
|
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
|
password: admin
|
||||||
profiles:
|
profiles:
|
||||||
active: dev
|
active: dev
|
||||||
|
redis:
|
||||||
|
lettuce:
|
||||||
|
pool:
|
||||||
|
max-active:
|
||||||
server:
|
server:
|
||||||
port: 6081
|
port: 6081
|
||||||
tomcat:
|
tomcat:
|
||||||
@ -23,6 +27,7 @@ management:
|
|||||||
web:
|
web:
|
||||||
base-path: /
|
base-path: /
|
||||||
|
|
||||||
|
|
||||||
log:
|
log:
|
||||||
level: info
|
level: info
|
||||||
path: /tmp/logs
|
path: /tmp/logs
|
||||||
|
Loading…
Reference in New Issue
Block a user