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

Add support for default values in property placeholder syntax [SPR-4785] #9462

Closed
spring-issuemaster opened this Issue May 6, 2008 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented May 6, 2008

Kenny MacLeod opened SPR-4785 and commented

I'd like to be able to specify the defaults for property placeholders within the placeholder itself, perhaps with something like this:

${my.property:myDefaultValue}

or something similar.

My use case is that often it is desirable to have to defaults alongside the placeholder, for readability. Also, our applications use a single, globally-defined placeholder configurer, and different instances of the application have different property sets, decoupled from the code itself. Embedding defaults within the placeholders would make this much easier to manage.


Affects: 2.5.4

Issue Links:

  • #10180 Property placeholder defaulting in resources path

3 votes, 5 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented May 6, 2008

Juergen Hoeller commented

Good news: Such placeholder defaulting has been discussed already and is very likely to make it into Spring 3.0!

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Feb 19, 2009

Ben Rowlands commented

An alternative syntax for separating the default is the ksh style "VALUE:-DEFAULT". It makes it slightly easier to read by adding extra distance between the variable name and the default. See "Korn Shell Variable Usage and Setting Rules" in:

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Sep 24, 2009

Juergen Hoeller commented

I went with the "${myKey:myDefaultValue}" defaulting syntax for 3.0 now. The separator is configurable through PropertyPlaceholderConfigurer's "valueSeparator" property, analogous to "placeholderPrefix" and "placeholderSuffix".

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment