Override application properties with system properties (implement in AppContext). #PL-6345

This commit is contained in:
Konstantin Krivopustov 2015-12-17 18:46:39 +00:00
parent 98ee152cc7
commit eb14d3ad04
4 changed files with 17 additions and 15 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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);

View File

@ -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);
}
/**