diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ResourceBanner.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ResourceBanner.java index ec8f6c5911..46108497df 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ResourceBanner.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ResourceBanner.java @@ -28,11 +28,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.boot.ansi.AnsiPropertySource; +import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertyResolver; -import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySourcesPropertyResolver; import org.springframework.core.io.Resource; import org.springframework.core.log.LogMessage; @@ -79,22 +79,15 @@ public class ResourceBanner implements Banner { protected List getPropertyResolvers(Environment environment, Class sourceClass) { MutablePropertySources propertySources = new MutablePropertySources(); - propertySources.addLast(getEnvironmentSource(environment)); + if (environment instanceof ConfigurableEnvironment) { + ((ConfigurableEnvironment) environment).getPropertySources().forEach(propertySources::addLast); + } propertySources.addLast(getTitleSource(sourceClass)); propertySources.addLast(getAnsiSource()); propertySources.addLast(getVersionSource(sourceClass)); return Collections.singletonList(new PropertySourcesPropertyResolver(propertySources)); } - private PropertySource getEnvironmentSource(Environment environment) { - return new PropertySource("environment", environment) { - @Override - public Object getProperty(String name) { - return environment.getProperty(name); - } - }; - } - private MapPropertySource getVersionSource(Class sourceClass) { return new MapPropertySource("version", getVersionsMap(sourceClass)); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ResourceBannerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ResourceBannerTests.java index dcd95a13ea..9960e78c9b 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ResourceBannerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ResourceBannerTests.java @@ -49,21 +49,6 @@ class ResourceBannerTests { AnsiOutput.setEnabled(Enabled.DETECT); } - @Test - void doNotUseDefaultsIfValueExists() { - Resource resource = new ByteArrayResource( - "banner ${a:def} ${spring-boot.version:def} ${application.version:def}".getBytes()); - String banner = printBanner(resource, "10.2", "1.0", null); - assertThat(banner).startsWith("banner 1 10.2 1.0"); - } - - @Test - void useDefaults() { - Resource resource = new ByteArrayResource("banner ${b:def1} ${c:def2} ${d:def3}".getBytes()); - String banner = printBanner(resource, null, null, null); - assertThat(banner).startsWith("banner def1 def2 def3"); - } - @Test void renderVersions() { Resource resource = new ByteArrayResource( @@ -142,6 +127,15 @@ class ResourceBannerTests { assertThat(banner).startsWith("banner 1"); } + @Test + void renderWithDefaultValues() { + Resource resource = new ByteArrayResource( + "banner ${a:default-a} ${b:default-b} ${spring-boot.version:default-boot-version} ${application.version:default-application-version}" + .getBytes()); + String banner = printBanner(resource, "10.2", "1.0", null); + assertThat(banner).startsWith("banner 1 default-b 10.2 1.0"); + } + private String printBanner(Resource resource, String bootVersion, String applicationVersion, String applicationTitle) { ResourceBanner banner = new MockResourceBanner(resource, bootVersion, applicationVersion, applicationTitle);