Skip to content

Banner placeholder and defaults do not work during development #44137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Saucistophe opened this issue Feb 5, 2025 · 5 comments
Closed

Banner placeholder and defaults do not work during development #44137

Saucistophe opened this issue Feb 5, 2025 · 5 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@Saucistophe
Copy link

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:

Image

But during aforementioned tests, I get this:

Image

@Saucistophe
Copy link
Author

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 5, 2025
@wilkinsona
Copy link
Member

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.

@wilkinsona wilkinsona added the for: team-meeting An issue we'd like to discuss as a team to make progress label Feb 5, 2025
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged for: team-meeting An issue we'd like to discuss as a team to make progress labels Feb 12, 2025
@philwebb philwebb added this to the 3.3.x milestone Feb 12, 2025
@wilkinsona
Copy link
Member

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.

@Saucistophe
Copy link
Author

I think this makes sense, if only for the sake of consistency. It's confusing to see that ${application.title} is resolved to an empty string, while ${non-existing-property} is rendered as-is.

@wilkinsona wilkinsona self-assigned this Feb 13, 2025
@wilkinsona
Copy link
Member

To clarify, the behaviour I described will only apply to well-known properties where we were forcing "" as the default value. Unknown properties will continue to be rendered as-is when the property hasn't been set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants