PropertyPlaceholderConfigurer supports "${myKey:myDefaultValue}" defaulting syntax
This commit is contained in:
@@ -99,6 +99,9 @@ public class PropertyPlaceholderConfigurer extends PropertyResourceConfigurer
|
||||
/** Default placeholder suffix: "}" */
|
||||
public static final String DEFAULT_PLACEHOLDER_SUFFIX = "}";
|
||||
|
||||
/** Default value separator: ":" */
|
||||
public static final String DEFAULT_VALUE_SEPARATOR = ":";
|
||||
|
||||
|
||||
/** Never check system properties. */
|
||||
public static final int SYSTEM_PROPERTIES_MODE_NEVER = 0;
|
||||
@@ -122,6 +125,8 @@ public class PropertyPlaceholderConfigurer extends PropertyResourceConfigurer
|
||||
|
||||
private String placeholderSuffix = DEFAULT_PLACEHOLDER_SUFFIX;
|
||||
|
||||
private String valueSeparator = DEFAULT_VALUE_SEPARATOR;
|
||||
|
||||
private int systemPropertiesMode = SYSTEM_PROPERTIES_MODE_FALLBACK;
|
||||
|
||||
private boolean searchSystemEnvironment = true;
|
||||
@@ -360,7 +365,8 @@ public class PropertyPlaceholderConfigurer extends PropertyResourceConfigurer
|
||||
private final PlaceholderResolver resolver;
|
||||
|
||||
public PlaceholderResolvingStringValueResolver(Properties props) {
|
||||
this.helper = new PropertyPlaceholderHelper(placeholderPrefix, placeholderSuffix, ignoreUnresolvablePlaceholders);
|
||||
this.helper = new PropertyPlaceholderHelper(
|
||||
placeholderPrefix, placeholderSuffix, valueSeparator, ignoreUnresolvablePlaceholders);
|
||||
this.resolver = new PropertyPlaceholderConfigurerResolver(props);
|
||||
}
|
||||
|
||||
@@ -370,6 +376,7 @@ public class PropertyPlaceholderConfigurer extends PropertyResourceConfigurer
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class PropertyPlaceholderConfigurerResolver implements PlaceholderResolver {
|
||||
|
||||
private final Properties props;
|
||||
|
||||
@@ -662,6 +662,19 @@ public final class PropertyResourceConfigurerTests {
|
||||
assertEquals("mytest", tb.getTouchy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyPlaceholderConfigurerWithInlineDefault() {
|
||||
factory.registerBeanDefinition("tb",
|
||||
genericBeanDefinition(TestBean.class)
|
||||
.addPropertyValue("touchy", "${test:mytest}").getBeanDefinition());
|
||||
|
||||
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
|
||||
ppc.postProcessBeanFactory(factory);
|
||||
|
||||
TestBean tb = (TestBean) factory.getBean("tb");
|
||||
assertEquals("mytest", tb.getTouchy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyPlaceholderConfigurerWithAliases() {
|
||||
factory.registerBeanDefinition("tb",
|
||||
|
||||
Reference in New Issue
Block a user