I have a need to do something like this:
bob.common=goat
bob.have=I have a {bob.common}!
bob.want=I want a {bob.common}!
bob.need=I need a {bob.common}!
Is this sort of thing possible? I know this seems silly, but being able to re-use a common piece is a need here, and we really can't (don't want to) do it programmatically.
We're already using numbered arguments in our properties, but we would like to be able to pass in a reference to another property.
I suggest to do this :
bob.common=goat
bob.have=I have a {0}!
bob.want=I want a {0}!
bob.need=I need a {0}!
Then in your page :
<spring:message code="bob.common" var="animal"/>
<spring:message code="bob.have" arguments="${animal}"/>
<spring:message code="bob.want" arguments="${animal}"/>
<spring:message code="bob.need" arguments="${animal}"/>
The way you want to do would be too strict, if you want to change your animal for example.
According to the Spring changelog, this has been supported since 2.5.3:
So for your example case, you should be able to use:
bob.have=I have a ${bob.common}!
and the PropertyPlaceholderConfigurer should recognise the "nested key" and resolve that correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With