Spring Framework
  1. Spring Framework
  2. SPR-4785

Add support for default values in property placeholder syntax

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.4
    • Fix Version/s: 3.0 RC1
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      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.

        Issue Links

          Activity

          Hide
          Juergen Hoeller added a comment -

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

          Juergen

          Show
          Juergen Hoeller added a comment - Good news: Such placeholder defaulting has been discussed already and is very likely to make it into Spring 3.0! Juergen
          Hide
          Ben Rowlands added a comment -

          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:

          Show
          Ben Rowlands added a comment - 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: http://www.bo.infn.it/alice/alice-doc/mll-doc/impgde/node16.html
          Hide
          Juergen Hoeller added a comment -

          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

          Show
          Juergen Hoeller added a comment - 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

            People

            • Assignee:
              Juergen Hoeller
              Reporter:
              Kenny MacLeod
              Last updater:
              Trevor Marshall
            • Votes:
              3 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                4 years, 30 weeks, 6 days ago