Ensure unresolvable placeholders can be ignored with @Value
Prior to this commit, if a PropertySourcesPlaceholderConfigurer bean
was configured with its ignoreUnresolvablePlaceholders flag set to
true, unresolvable placeholders in an @Value annotation were not
ignored, resulting in a BeanCreationException for the bean using @Value.
For example, given a property declared as `my.app.var = ${var}` without
a corresponding `var` property declared, an attempt to resolve
`@Value("${my.app.var}")` resulted in the following exception.
java.lang.IllegalArgumentException: Could not resolve placeholder 'var' in value "${var}"
This commit fixes this by modifying
PropertySourcesPlaceholderConfigurer's postProcessBeanFactory(...)
method so that a local PropertyResolver is created if the
ignoreUnresolvablePlaceholders flag is set to true. The local
PropertyResolver then enforces that flag, since the Environment in the
ApplicationContext is most likely not configured with
ignoreUnresolvablePlaceholders set to true.
Closes gh-27947
@ -129,12 +132,25 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS
@@ -129,12 +132,25 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS
@ -159,8 +167,11 @@ public class PropertySourcesPlaceholderConfigurerTests {
@@ -159,8 +167,11 @@ public class PropertySourcesPlaceholderConfigurerTests {
.withMessage("Could not resolve placeholder 'my.name' in value \"${my.name}\"");
}
@Test
@ -177,6 +188,38 @@ public class PropertySourcesPlaceholderConfigurerTests {
@@ -177,6 +188,38 @@ public class PropertySourcesPlaceholderConfigurerTests {
@ -402,4 +445,30 @@ public class PropertySourcesPlaceholderConfigurerTests {
@@ -402,4 +445,30 @@ public class PropertySourcesPlaceholderConfigurerTests {