I've always wanted to have a fancy banner that works in production AND during development.
But if you start with a fresh springboot project and run it from your ide, or with mvn spring-boot:run
, or during tests, values are not interpreted AND the defaults don't show up either.
I raised a similar isue in #34713 but it's not working in development runs.
To test this, I put this in src/main/resources/banner.txt
:
Coloring : ${Ansi.BLUE}Blue text${AnsiColor.DEFAULT}
Styling : ${AnsiStyle.BOLD}BOLD text${AnsiStyle.NORMAL}
!! Without defaults !!
application.version : ${application.version}
application.formatted-version : ${application.formatted-version}
spring-boot.version : ${spring-boot.version}
spring-boot.formatted-version : ${spring-boot.formatted-version}
application.title : ${application.title}
non-existing-property : ${non-existing-property}
!! With defaults !!
application.version : ${application.version:123}
application.formatted-version : ${application.formatted-version:v123}
spring-boot.version : ${spring-boot.version:456}
spring-boot.formatted-version : ${spring-boot.formatted-version:version456}
application.title : ${application.title:TiTlE}
non-existing-property : ${non-existing-property:non-existing-property}
It renders OK if I start the jar with java -jar target/demo-0.0.1-SNAPSHOT.jar
:
But during aforementioned tests, I get this:
Comment From: Saucistophe
I get that the manifest is not available and no sensible value can be infer without messing with the current implementation, but the default values should cover this, and they fail to render.
Comment From: wilkinsona
The problem is that the properties that are "missing" actually have empty string values. Placeholder resolution then uses these empty strings rather than the fallback specified in the placeholder. We could change ResourceBanner
to omit the properties rather than using ""
. Doing so produces the following output:
Coloring : Blue text
Styling : BOLD text
!! Without defaults !!
application.version : ${application.version}
application.formatted-version : ${application.formatted-version}
spring-boot.version : 3.4.2
spring-boot.formatted-version : (v3.4.2)
application.title : ${application.title}
non-existing-property : ${non-existing-property}
!! With defaults !!
application.version : 123
application.formatted-version : v123
spring-boot.version : 3.4.2
spring-boot.formatted-version : (v3.4.2)
application.title : TiTlE
non-existing-property : non-existing-property
This has fixed the output with defaults but has changed the output without defaults. That change could be unwanted for some so we'll have to consider our options here.
Comment From: wilkinsona
We discussed this today and we'd like to change things so that the default value in the placeholder is used. If there's no default value in the placeholder, we'd like an empty string to appear in the output rather than the placeholder.