org.springframework.context.support
Class ReloadableResourceBundleMessageSource

org.springframework.context.support.AbstractNestingMessageSource
  |
  +--org.springframework.context.support.ReloadableResourceBundleMessageSource

public class ReloadableResourceBundleMessageSource
extends AbstractNestingMessageSource
implements ApplicationContextAware

MessageSource that accesses the ResourceBundles with the specified basenames. This class uses java.util.Properties instances as its internal data structure for messages.

In contrast to ResourceBundleMessageSoruce, this class supports reloading of properties files through the "cacheSeconds" setting, and also through programmatically clearing the properties cache. Since application servers do typcially cache all files loaded from the classpath, it is necessary to store resources somewhere else (for example, in the "WEB-INF" directory of a web app). Otherwise changes of files in the classpath are not reflected in the application.

Note that the "basename" respectively "basenames" property has a different convention here: It follows the basic ResourceBundle rule of not specifying file extension or language codes, but can refer to any Spring resource location (instead of being restricted to classpath resources). With a "classpath:" prefix, resources can still be loaded from the classpath, but "cacheSeconds" values other than "-1" (caching forever) will not work in this case.

Author:
Thomas Achleitner, Juergen Hoeller
See Also: setCacheSeconds(int), setBasenames(java.lang.String[]), ResourceBundleMessageSource, ResourceBundle

Field Summary
 final static StringPROPERTIES_SUFFIX
           

Method Summary
 synchronized voidclearCache()
          Clear the resource bundle cache.
 voidsetApplicationContext(ApplicationContext context)
           
 voidsetBasename(String basename)
          Set a single basename, following the basic ResourceBundle convention of not specifying file extension or language codes, but in contrast to ResourceBundleMessageSource referring to a Spring resource location: e.g.
 voidsetBasenames(String[] basenames)
          Set an array of basenames, each following the above-mentioned special convention.
 voidsetCacheSeconds(int cacheSeconds)
          Set the number of seconds to cache loaded properties files.
 voidsetFallbackToSystemLocale(boolean fallbackToSystemLocale)
          Set whether to fall back to the system Locale if no files for a specific Locale have been found.
 StringtoString()
           

Methods inherited from class org.springframework.context.support.AbstractNestingMessageSource
getMessage, getMessage, getMessage, setParent, setUseCodeAsDefaultMessage

Field Detail

PROPERTIES_SUFFIX

public final static String PROPERTIES_SUFFIX
Method Detail

clearCache

public synchronized void clearCache()
Clear the resource bundle cache. Following resolve calls will lead to reloading of the properties files.

setApplicationContext

public void setApplicationContext(ApplicationContext context)

setBasename

public void setBasename(String basename)
Set a single basename, following the basic ResourceBundle convention of not specifying file extension or language codes, but in contrast to ResourceBundleMessageSource referring to a Spring resource location: e.g. "WEB-INF/messages" for "WEB-INF/messages.properties", "WEB-INF/messages_en.properties", etc.
Parameters:
basename - the single basename
See Also:
setBasenames(java.lang.String[]), ResourceEditor, ResourceBundle

setBasenames

public void setBasenames(String[] basenames)
Set an array of basenames, each following the above-mentioned special convention. The associated resource bundles will be checked sequentially when resolving a message code.

Note that message definitions in a previous resource bundle will override ones in a later bundle, due to the sequential lookup.

Parameters:
basenames - an array of basenames
See Also:
setBasename(java.lang.String), ResourceBundle

setCacheSeconds

public void setCacheSeconds(int cacheSeconds)
Set the number of seconds to cache loaded properties files.

setFallbackToSystemLocale

public void setFallbackToSystemLocale(boolean fallbackToSystemLocale)
Set whether to fall back to the system Locale if no files for a specific Locale have been found. Default is true; if this is turned off, the only fallback will be the default file (e.g. "messages.properties" for basename "messages").

Falling back to the system Locale is the default behavior of java.util.ResourceBundle. However, this is often not desirable in an application server environment, where the system Locale is not relevant to the application at all: Set this flag to "false" in such a scenario.


toString

public String toString()

Association Links

to Class java.lang.String

to Class org.springframework.context.ApplicationContext

to Class java.lang.String

to Class java.util.Map

Cache to hold filename lists per Locale

to Class java.util.Map

Cache to hold already loaded properties per filename