Skip to content

ResourceBundleMessageSource should allow for custom PropertyResourceBundle subclass [SPR-12666] #17265

@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions