Search code examples
springapplication.properties

How to get Spring property with embedded property variable as a literal


I currently have a Spring application.properties with 2 properties defined as follows:

validator.url=http://location.com/${domain}/${family}
query.validator.url=${validator.url}

Currently my application resolves query.validator.url to be ${validator.url} is there anyway that I can have it resolve to the same value as validator.url which is http://location.com/${domain}/${family}

Note: ${domain} and ${family} don't resolve, they are handled in code.


Solution

  • Try the following:

    validator.url=http://location.com/#{'$'}{domain}/#{'$'}{family}
    query.validator.url=${validator.url}
    

    Both validator.url and query.validator.url will resolve to http://location.com/${domain}/${family}

    Alternatively, you can create a property for the $, which you can then use inside validator.url, e.g.:

    var=$
    validator.url=http://location.com/${var}{domain}/${var}{family}
    

    There's an issue regarding this on Spring's JIRA