I am using the spring @Value annotation to load a property into my controller from a file.
In my controller....
@Value("#{messagesProperties['confirm.priceOverride.fourWeeksOrMore']}")
public String recallOfFourWeeksOrMoreConfirm = null;
In my messagesProperties properties file...
confirm.priceOverride.fourWeeksOrMore=You have chosen to recall historical data older than four weeks of age. Do you wish to continue?
This works but I would now like to put a placeholder in the property file to replace the word four. For example...
confirm.priceOverride.fourWeeksOrMore=You have chosen to recall historical data older than {0} weeks of age. Do you wish to continue?
The {0} specified in the properties file will be replaced with a value returned from the database which I can get using the following code...
Integer priceOverrideRetentionDays = appParamsManager.getPriceOverrideRetentionDays();
I have worked out a way to achieve what I want which is as follows...
Integer priceOverrideRetentionDays = appParamsManager.getPriceOverrideRetentionDays();
recallOfFourWeeksOrMoreConfirm = MessageFormat.format(recallOfFourWeeksOrMoreConfirm, priceOverrideRetentionDays.toString());
But I would like to know if there is some way I can do MessageFormat code in the @Value annotation using spring expression language. I've never written a custom spring expression function before, that would be acceptable but I'm not sure how to register it etc.
thanks for your help.
Can someone please help me with how?
thanks
Aucun commentaire:
Enregistrer un commentaire