Class ResourceBundleMessageSource

All Implemented Interfaces:
Aware, BeanClassLoaderAware, HierarchicalMessageSource, MessageSource

public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSource implements BeanClassLoaderAware
MessageSource implementation that accesses resource bundles using specified basenames. This class relies on the underlying JDK's ResourceBundle implementation, in combination with the JDK's standard message parsing provided by MessageFormat.

This MessageSource caches both the accessed ResourceBundle instances and the generated MessageFormats for each message. It also implements rendering of no-arg messages without MessageFormat, as supported by the AbstractMessageSource base class. The caching provided by this MessageSource is significantly faster than the built-in caching of the java.util.ResourceBundle class.

The basenames follow ResourceBundle conventions: essentially, a fully-qualified classpath location. If it doesn't contain a package qualifier (such as org.mypackage), it will be resolved from the classpath root. Note that the JDK's standard ResourceBundle treats dots as package separators: This means that "test.theme" is effectively equivalent to "test/theme".

On the classpath, bundle resources will be read with the locally configured encoding: by default, ISO-8859-1; consider switching this to UTF-8, or to null for the platform default encoding. On the JDK 9+ module path where locally provided ResourceBundle.Control handles are not supported, this MessageSource always falls back to ResourceBundle.getBundle(java.lang.String) retrieval with the platform default encoding: UTF-8 with a ISO-8859-1 fallback on JDK 9+ (configurable through the "java.util.PropertyResourceBundle.encoding" system property). Note that loadBundle(Reader)/loadBundle(InputStream) won't be called in this case either, effectively ignoring overrides in subclasses. Consider implementing a JDK 9 java.util.spi.ResourceBundleProvider instead.

Rod Johnson, Juergen Hoeller, Qimiao Chen
See Also:
  • Constructor Details

    • ResourceBundleMessageSource

      public ResourceBundleMessageSource()
  • Method Details