org.springframework.context.support

## 类 ResourceBundleMessageSource

- java.lang.Object
- - org.springframework.context.support.MessageSourceSupport
  - - org.springframework.context.support.AbstractMessageSource
    - - org.springframework.context.support.AbstractResourceBasedMessageSource
      - - org.springframework.context.support.ResourceBundleMessageSource

- 所有已实现的接口:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, HierarchicalMessageSource, MessageSource

      public class ResourceBundleMessageSource
      extends AbstractResourceBasedMessageSource
      implements org.springframework.beans.factory.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".

  作者:
    Rod Johnson, Juergen Hoeller
  另请参阅:
    `AbstractResourceBasedMessageSource.setBasenames(java.lang.String...)`, `ReloadableResourceBundleMessageSource`, `ResourceBundle`, `MessageFormat`

- - ### 字段概要

    - ### 从类继承的字段 org.springframework.context.support.MessageSourceSupport

      `logger`

  - ### 构造器概要

    构造器
    构造器和说明
    `ResourceBundleMessageSource()`

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `protected ResourceBundle` | `doGetBundle(String basename, Locale locale)` Obtain the resource bundle for the given basename and Locale.
    `protected ClassLoader` | `getBundleClassLoader()` Return the ClassLoader to load resource bundles with.
    `protected MessageFormat` | `getMessageFormat(ResourceBundle bundle, String code, Locale locale)` Return a MessageFormat for the given bundle and code, fetching already generated MessageFormats from the cache.
    `protected ResourceBundle` | `getResourceBundle(String basename, Locale locale)` Return a ResourceBundle for the given basename and code, fetching already generated MessageFormats from the cache.
    `protected String` | `getStringOrNull(ResourceBundle bundle, String key)` Efficiently retrieve the String value for the specified key, or return `null` if not found.
    `protected ResourceBundle` | `loadBundle(Reader reader)` Load a property-based resource bundle from the given reader.
    `protected MessageFormat` | `resolveCode(String code, Locale locale)` Resolves the given message code as key in the registered resource bundles, using a cached MessageFormat instance per message code.
    `protected String` | `resolveCodeWithoutArguments(String code, Locale locale)` Resolves the given message code as key in the registered resource bundles, returning the value found in the bundle as-is (without MessageFormat parsing).
    `void` | `setBeanClassLoader(ClassLoader classLoader)`
    `void` | `setBundleClassLoader(ClassLoader classLoader)` Set the ClassLoader to load resource bundles with.
    `String` | `toString()` Show the configuration of this MessageSource.

    - ### 从类继承的方法 org.springframework.context.support.AbstractResourceBasedMessageSource

      `addBasenames, getBasenameSet, getCacheMillis, getDefaultEncoding, isFallbackToSystemLocale, setBasename, setBasenames, setCacheMillis, setCacheSeconds, setDefaultEncoding, setFallbackToSystemLocale`

    - ### 从类继承的方法 org.springframework.context.support.AbstractMessageSource

      `getCommonMessages, getDefaultMessage, getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isUseCodeAsDefaultMessage, resolveArguments, setCommonMessages, setParentMessageSource, setUseCodeAsDefaultMessage`

    - ### 从类继承的方法 org.springframework.context.support.MessageSourceSupport

      `createMessageFormat, formatMessage, isAlwaysUseMessageFormat, renderDefaultMessage, setAlwaysUseMessageFormat`

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### 构造器详细资料

    - #### ResourceBundleMessageSource

          public ResourceBundleMessageSource()

  - ### 方法详细资料

    - #### setBundleClassLoader

          public void setBundleClassLoader(ClassLoader classLoader)

      Set the ClassLoader to load resource bundles with.

      Default is the containing BeanFactory's `bean ClassLoader`, or the default ClassLoader determined by `ClassUtils.getDefaultClassLoader()` if not running within a BeanFactory.

    - #### getBundleClassLoader

          @Nullable
          protected ClassLoader getBundleClassLoader()

      Return the ClassLoader to load resource bundles with.

      Default is the containing BeanFactory's bean ClassLoader.

      另请参阅:
        `setBundleClassLoader(java.lang.ClassLoader)`

    - #### setBeanClassLoader

          public void setBeanClassLoader(ClassLoader classLoader)

      指定者:
        `setBeanClassLoader` 在接口中 `org.springframework.beans.factory.BeanClassLoaderAware`

    - #### resolveCodeWithoutArguments

          protected String resolveCodeWithoutArguments(String code,
                                                       Locale locale)

      Resolves the given message code as key in the registered resource bundles, returning the value found in the bundle as-is (without MessageFormat parsing).
      覆盖:
        `resolveCodeWithoutArguments` 在类中 `AbstractMessageSource`
      参数:
        `code` - the code of the message to resolve
        `locale` - the locale to resolve the code for (subclasses are encouraged to support internationalization)
      返回:
        the message String, or `null` if not found
      另请参阅:
        `AbstractMessageSource.resolveCode(java.lang.String, java.util.Locale)`, `MessageFormat`

    - #### resolveCode

          @Nullable
          protected MessageFormat resolveCode(String code,
                                                         Locale locale)

      Resolves the given message code as key in the registered resource bundles, using a cached MessageFormat instance per message code.
      指定者:
        `resolveCode` 在类中 `AbstractMessageSource`
      参数:
        `code` - the code of the message to resolve
        `locale` - the locale to resolve the code for (subclasses are encouraged to support internationalization)
      返回:
        the MessageFormat for the message, or `null` if not found
      另请参阅:
        `AbstractMessageSource.resolveCodeWithoutArguments(String, java.util.Locale)`

    - #### getResourceBundle

          @Nullable
          protected ResourceBundle getResourceBundle(String basename,
                                                                Locale locale)

      Return a ResourceBundle for the given basename and code, fetching already generated MessageFormats from the cache.
      参数:
        `basename` - the basename of the ResourceBundle
        `locale` - the Locale to find the ResourceBundle for
      返回:
        the resulting ResourceBundle, or `null` if none found for the given basename and Locale

    - #### doGetBundle

          protected ResourceBundle doGetBundle(String basename,
                                               Locale locale)
                                        throws MissingResourceException

      Obtain the resource bundle for the given basename and Locale.
      参数:
        `basename` - the basename to look for
        `locale` - the Locale to look for
      返回:
        the corresponding ResourceBundle
      抛出:
        `MissingResourceException` - if no matching bundle could be found
      另请参阅:
        `ResourceBundle.getBundle(String, Locale, ClassLoader)`, `getBundleClassLoader()`

    - #### loadBundle

          protected ResourceBundle loadBundle(Reader reader)
                                       throws IOException

      Load a property-based resource bundle from the given reader.

      The default implementation returns a `PropertyResourceBundle`.

      参数:
        `reader` - the reader for the target resource
      返回:
        the fully loaded bundle
      抛出:
        `IOException` - in case of I/O failure
      从以下版本开始:
        4.2
      另请参阅:
        `PropertyResourceBundle.PropertyResourceBundle(Reader)`

    - #### getMessageFormat

          @Nullable
          protected MessageFormat getMessageFormat(ResourceBundle bundle,
                                                              String code,
                                                              Locale locale)
                                                       throws MissingResourceException

      Return a MessageFormat for the given bundle and code, fetching already generated MessageFormats from the cache.
      参数:
        `bundle` - the ResourceBundle to work on
        `code` - the message code to retrieve
        `locale` - the Locale to use to build the MessageFormat
      返回:
        the resulting MessageFormat, or `null` if no message defined for the given code
      抛出:
        `MissingResourceException` - if thrown by the ResourceBundle

    - #### getStringOrNull

          @Nullable
          protected String getStringOrNull(ResourceBundle bundle,
                                                      String key)

      Efficiently retrieve the String value for the specified key, or return `null` if not found.

      As of 4.2, the default implementation checks `containsKey` before it attempts to call `getString` (which would require catching `MissingResourceException` for key not found).

      Can be overridden in subclasses.

      参数:
        `bundle` - the ResourceBundle to perform the lookup in
        `key` - the key to look up
      返回:
        the associated value, or `null` if none
      从以下版本开始:
        4.2
      另请参阅:
        `ResourceBundle.getString(String)`, `ResourceBundle.containsKey(String)`

    - #### toString

          public String toString()

      Show the configuration of this MessageSource.
      覆盖:
        `toString` 在类中 `Object`