-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Dave Jarvis opened SPR-12666 and commented
Property files, resource bundles, and therefore property resources bundles incur a lot of duplication (in practice) because there is no way for one entry to refer to other entries.
Lines 431 to 433 of org.springframework.context.support.ResourceBundleMessageSource hard-code a specific instance of PropertyResourceBundle:
return (defaultEncoding != null ?
new PropertyResourceBundle(new InputStreamReader(stream, defaultEncoding)) :
new PropertyResourceBundle(stream));
These lines should be:
return (defaultEncoding != null ?
createPropertyResourceBundle(new InputStreamReader(stream, defaultEncoding)) :
createPropertyResourceBundle(stream));
Then two corresponding protected methods "createPropertyResourceBundle" should be created (with one calling the other). For example:
protected PropertyResourceBundle createPropertyResourceBundle( InputStream stream ) {
return createPropertyResourceBundle( stream, Locale.getDefaultEncoding() );
}
This would allow for systems to override the specific type of PropertyResourceBundle. Once in place, it is then possible to write properties that refer to other properties, such as:
app.title=Spring Framework
app.login=Please log in to the ${app.title} to continue.
app.contact.thanks=Thank you for your suggestions to improve the ${app.title}.
Currently, this is not possible due to lines 431 - 433.
Affects: 4.1.4
Issue Links:
- ResourceBundleMessageSource should avoid ResourceBundle.Control on Jigsaw [SPR-16776] #21316 ResourceBundleMessageSource should avoid ResourceBundle.Control on Jigsaw
- Method getMergedProperties in ReloadableResourceBundleMessageSource does not set fileTimestamp [SPR-14583] #19152 Method getMergedProperties in ReloadableResourceBundleMessageSource does not set fileTimestamp