PropertySourcesPlaceholderConfigurer's "ignoreUnresolvablePlaceholders" setting reliably applies to nested placeholders as well
Issue: SPR-10549
(cherry picked from commit 127b91f)
This commit is contained in:
@@ -153,6 +153,25 @@ public class PropertyResourceConfigurerIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyPlaceholderConfigurerWithNestedUnresolvableReference() {
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.add("name", "name${var}");
|
||||
ac.registerSingleton("tb1", TestBean.class, pvs);
|
||||
pvs = new MutablePropertyValues();
|
||||
pvs.add("properties", "var=${m}var\nm=${var2}\nvar2=${m2}");
|
||||
ac.registerSingleton("configurer1", PropertyPlaceholderConfigurer.class, pvs);
|
||||
try {
|
||||
ac.refresh();
|
||||
fail("Should have thrown BeanDefinitionStoreException");
|
||||
}
|
||||
catch (BeanDefinitionStoreException ex) {
|
||||
// expected
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore // this test was breaking after the 3.0 repackaging
|
||||
@Test
|
||||
public void testPropertyPlaceholderConfigurerWithAutowireByType() {
|
||||
|
||||
@@ -39,8 +39,6 @@ import org.springframework.mock.env.MockPropertySource;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PropertySourcesPlaceholderConfigurer}.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
@@ -139,7 +137,9 @@ public class PropertySourcesPlaceholderConfigurerTests {
|
||||
|
||||
PropertySourcesPlaceholderConfigurer pc = new PropertySourcesPlaceholderConfigurer();
|
||||
pc.setPropertySources(propertySources);
|
||||
pc.setProperties(new Properties() {{ put("my.name", "local"); }});
|
||||
pc.setProperties(new Properties() {{
|
||||
put("my.name", "local");
|
||||
}});
|
||||
pc.setIgnoreUnresolvablePlaceholders(true);
|
||||
pc.postProcessBeanFactory(bf);
|
||||
assertThat(bf.getBean(TestBean.class).getName(), equalTo("${my.name}"));
|
||||
@@ -172,6 +172,38 @@ public class PropertySourcesPlaceholderConfigurerTests {
|
||||
assertThat(bf.getBean(TestBean.class).getName(), equalTo("${my.name}"));
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void nestedUnresolvablePlaceholder() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerBeanDefinition("testBean",
|
||||
genericBeanDefinition(TestBean.class)
|
||||
.addPropertyValue("name", "${my.name}")
|
||||
.getBeanDefinition());
|
||||
|
||||
PropertySourcesPlaceholderConfigurer pc = new PropertySourcesPlaceholderConfigurer();
|
||||
pc.setProperties(new Properties() {{
|
||||
put("my.name", "${bogus}");
|
||||
}});
|
||||
pc.postProcessBeanFactory(bf); // should throw
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ignoredNestedUnresolvablePlaceholder() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerBeanDefinition("testBean",
|
||||
genericBeanDefinition(TestBean.class)
|
||||
.addPropertyValue("name", "${my.name}")
|
||||
.getBeanDefinition());
|
||||
|
||||
PropertySourcesPlaceholderConfigurer pc = new PropertySourcesPlaceholderConfigurer();
|
||||
pc.setProperties(new Properties() {{
|
||||
put("my.name", "${bogus}");
|
||||
}});
|
||||
pc.setIgnoreUnresolvablePlaceholders(true);
|
||||
pc.postProcessBeanFactory(bf);
|
||||
assertThat(bf.getBean(TestBean.class).getName(), equalTo("${bogus}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNonEnumerablePropertySource() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
@@ -213,7 +245,8 @@ public class PropertySourcesPlaceholderConfigurerTests {
|
||||
ppc.postProcessBeanFactory(bf);
|
||||
if (override) {
|
||||
assertThat(bf.getBean(TestBean.class).getName(), equalTo("local"));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
assertThat(bf.getBean(TestBean.class).getName(), equalTo("enclosing"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user