diff --git a/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java b/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java index eec7a3e1db..899b8402d0 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java @@ -289,6 +289,7 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc String targetName = (StringUtils.hasLength(annotation.value()) ? annotation .value() : annotation.prefix()); if (StringUtils.hasLength(targetName)) { + targetName = this.environment.resolvePlaceholders(targetName); factory.setTargetName(targetName); } } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java index dedf4bf375..9d5dee1d86 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java @@ -148,6 +148,16 @@ public class ConfigurationPropertiesBindingPostProcessorTests { equalTo("foo")); } + @Test + public void placeholderInPrefix() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + EnvironmentTestUtils.addEnvironment(this.context, "foo:spam", "spam.foo:bar"); + this.context.register(PlaceholderPrefixConfiguration.class); + this.context.refresh(); + assertThat(this.context.getBean(PlaceholderPrefixConfiguration.class).getFoo(), + equalTo("bar")); + } + @Test public void placeholderResolutionWithCustomLocation() throws Exception { this.context = new AnnotationConfigApplicationContext(); @@ -373,6 +383,22 @@ public class ConfigurationPropertiesBindingPostProcessorTests { } + @EnableConfigurationProperties + @ConfigurationProperties(prefix = "${foo:bar}") + public static class PlaceholderPrefixConfiguration { + + private String foo; + + public String getFoo() { + return this.foo; + } + + public void setFoo(String foo) { + this.foo = foo; + } + + } + @EnableConfigurationProperties @ConfigurationProperties(locations = "custom-location.yml") public static class CustomConfigurationLocation {