The ResourceBanner uses placeholders with the regular syntax ${variable.name} syntax.
There are only a few variables supported, which is fine; and some of them, such as the application version, is not resolved when starting the project from IDE (as opposed from the jar).
I wanted to use default values, for instance ${application.version:dev}; when I do that, the printed version becomes dev regardless of whether it's defined.
I reproduced the issue in unit tests in ResourceBannerTests, and I think it is due to the way we handle resolvers:
for (PropertyResolver resolver : getPropertyResolvers(environment, sourceClass)) {
banner = resolver.resolvePlaceholders(banner);
}
If the first resolver fails to find the value, it outputs the default value and it's final.
Comment From: krzyk
@philwebb Can I work on this one?
Comment From: wilkinsona
It's all yours, @krzyk. Thank you.
Comment From: Saucistophe
If that can help, here is the test I wrote:
@Test
void renderDefaultValues() {
Resource resource = new ByteArrayResource(
"banner ${a}${spring-boot.formatted-version:default-value}".getBytes());
String banner = printBanner(resource, "10.2", "2.0", null);
assertThat(banner).startsWith("banner 1 (v10.2)");
}
..Which yields:
java.lang.AssertionError:
Expecting actual:
"banner 1default-value
"
to start with:
"banner 1 (v10.2)"
Comment From: wilkinsona
Closing in favor of #34764. Thanks for the PR, @krzyk.