Skip to content
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-projects-issues opened this issue May 6, 2008 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues 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:

3 votes, 5 watchers

@spring-projects-issues
Copy link
Collaborator Author

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-projects-issues
Copy link
Collaborator Author

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-projects-issues
Copy link
Collaborator Author

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
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants