mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 20:28:00 +08:00
Override application properties with system properties (implement in AppContext). #PL-6345
This commit is contained in:
parent
98ee152cc7
commit
eb14d3ad04
@ -42,14 +42,10 @@ public class ConfigPersisterClientImpl implements ConfigPersister {
|
||||
value = System.getProperty(name);
|
||||
break;
|
||||
case APP:
|
||||
value = System.getProperty(name);
|
||||
if (StringUtils.isEmpty(value))
|
||||
value = AppContext.getProperty(name);
|
||||
value = AppContext.getProperty(name);
|
||||
break;
|
||||
case DATABASE:
|
||||
value = System.getProperty(name);
|
||||
if (StringUtils.isEmpty(value))
|
||||
value = AppContext.getProperty(name);
|
||||
value = AppContext.getProperty(name);
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
if (caching) {
|
||||
loadCache();
|
||||
|
@ -28,14 +28,10 @@ public class ConfigPersisterImpl implements ConfigPersister {
|
||||
value = System.getProperty(name);
|
||||
break;
|
||||
case APP:
|
||||
value = System.getProperty(name);
|
||||
if (StringUtils.isEmpty(value))
|
||||
value = AppContext.getProperty(name);
|
||||
value = AppContext.getProperty(name);
|
||||
break;
|
||||
case DATABASE:
|
||||
value = System.getProperty(name);
|
||||
if (StringUtils.isEmpty(value))
|
||||
value = AppContext.getProperty(name);
|
||||
value = AppContext.getProperty(name);
|
||||
if (StringUtils.isEmpty(value))
|
||||
value = getConfigStorageAPI().getDbProperty(name);
|
||||
break;
|
||||
|
@ -192,6 +192,7 @@ public class ConfigProviderTest {
|
||||
assertTrue(config.getBooleanPropDef());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSystemPropOverridesAppProp() throws Exception {
|
||||
TestConfig config = AppBeans.get(Configuration.class).getConfig(TestConfig.class);
|
||||
|
||||
|
@ -6,6 +6,7 @@ package com.haulmont.cuba.core.sys;
|
||||
|
||||
import com.haulmont.bali.datastruct.Pair;
|
||||
import com.haulmont.cuba.core.sys.logging.LogMdc;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@ -103,15 +104,23 @@ public class AppContext {
|
||||
return getDeprecatedProperty(pair);
|
||||
}
|
||||
}
|
||||
return properties.get(key);
|
||||
return getSystemOrAppProperty(key);
|
||||
}
|
||||
|
||||
private static String getDeprecatedProperty(Pair<String, String> pair) {
|
||||
String value = properties.get(pair.getSecond());
|
||||
String value = getSystemOrAppProperty(pair.getSecond());
|
||||
if (value != null)
|
||||
return value;
|
||||
else
|
||||
return properties.get(pair.getFirst());
|
||||
return getSystemOrAppProperty(pair.getFirst());
|
||||
}
|
||||
|
||||
private static String getSystemOrAppProperty(String key) {
|
||||
String value = System.getProperty(key);
|
||||
if (StringUtils.isNotEmpty(value))
|
||||
return value;
|
||||
else
|
||||
return properties.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user