Class ReloadableResourceBundleExpressionSource
- All Implemented Interfaces:
- Aware,- ResourceLoaderAware,- ExpressionSource
ExpressionSource implementation that accesses resource bundles using specified basenames.
 This class uses Properties instances as its custom data structure for expressions,
 loading them via a PropertiesPersister strategy: The default
 strategy is capable of loading properties files with a specific character encoding, if desired.- Since:
- 2.0
- Author:
- Juergen Hoeller, Mark Fisher, Gary Russell, Artem Bilan, Christian Tzolov
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidClear the resource bundle cache.getExpression(String key, Locale locale) Resolves the given key in the retrieved bundle files to an Expression.voidsetBasename(String basename) Set a single basename, following the basic ResourceBundle convention of not specifying file extension or language codes, but referring to a Spring resource location: e.g.voidsetBasenames(String[] basenames) Set an array of basenames, each following the basic ResourceBundle convention of not specifying file extension or language codes, but referring to a Spring resource location: e.g.voidsetCacheSeconds(int cacheSeconds) Set the number of seconds to cache loaded properties files.voidsetDefaultEncoding(String defaultEncoding) Set the default charset to use for parsing properties files.voidsetFallbackToSystemLocale(boolean fallbackToSystemLocale) Set whether to fall back to the system Locale if no files for a specific Locale have been found.voidsetFileEncodings(Properties fileEncodings) Set per-file charsets to use for parsing properties files.voidsetPropertiesPersister(PropertiesPersister propertiesPersister) Set the PropertiesPersister to use for parsing properties files.voidsetResourceLoader(ResourceLoader resourceLoader) Set the ResourceLoader to use for loading bundle properties files.toString()
- 
Constructor Details- 
ReloadableResourceBundleExpressionSourcepublic ReloadableResourceBundleExpressionSource()
 
- 
- 
Method Details- 
setBasenameSet a single basename, following the basic ResourceBundle convention of not specifying file extension or language codes, but referring to a Spring resource location: e.g. "META-INF/expressions" for "META-INF/expressions.properties", "META-INF/expressions_en.properties", etc.XML properties files are also supported: .g. "META-INF/expressions" will find and load "META-INF/expressions.xml", "META-INF/expressions_en.xml", etc as well. - Parameters:
- basename- the single basename
- See Also:
 
- 
setBasenamesSet an array of basenames, each following the basic ResourceBundle convention of not specifying file extension or language codes, but referring to a Spring resource location: e.g. "META-INF/expressions" for "META-INF/expressions.properties", "META-INF/expressions_en.properties", etc.XML properties files are also supported: .g. "META-INF/expressions" will find and load "META-INF/expressions.xml", "META-INF/expressions_en.xml", etc as well. The associated resource bundles will be checked sequentially when resolving an expression key. Note that expression 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:
 
- 
setDefaultEncodingSet the default charset to use for parsing properties files. Used if no file-specific charset is specified for a file.Default is none, using the java.util.Propertiesdefault encoding.Only applies to classic properties files, not to XML files. - Parameters:
- defaultEncoding- the default charset
- See Also:
 
- 
setFileEncodingsSet per-file charsets to use for parsing properties files.Only applies to classic properties files, not to XML files. - Parameters:
- fileEncodings- Properties with filenames as keys and charset names as values. Filenames have to match the basename syntax, with optional locale-specific appendices: e.g. "META-INF/expressions" or "META-INF/expressions_en".
- See Also:
 
- 
setFallbackToSystemLocalepublic 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. "expressions.properties" for basename "expressions").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.- Parameters:
- fallbackToSystemLocale- true to fall back.
 
- 
setCacheSecondspublic void setCacheSeconds(int cacheSeconds) Set the number of seconds to cache loaded properties files.- Default is "-1", indicating to cache forever (just like
 java.util.ResourceBundle).
- A positive number will cache loaded properties files for the given number of seconds. This is essentially the interval between refresh checks. Note that a refresh attempt will first check the last-modified timestamp of the file before actually reloading it; so if files don't change, this interval can be set rather low, as refresh attempts will not actually reload.
- A value of "0" will check the last-modified timestamp of the file on every expression access. Do not use this in a production environment!
 - Parameters:
- cacheSeconds- The cache seconds.
 
- Default is "-1", indicating to cache forever (just like
 
- 
setPropertiesPersisterSet the PropertiesPersister to use for parsing properties files.The default is a DefaultPropertiesPersister. - Parameters:
- propertiesPersister- The properties persister.
- See Also:
 
- 
setResourceLoaderSet the ResourceLoader to use for loading bundle properties files.The default is a DefaultResourceLoader. Will get overridden by the ApplicationContext if running in a context, as it implements the ResourceLoaderAware interface. Can be manually overridden when running outside of an ApplicationContext. - Specified by:
- setResourceLoaderin interface- ResourceLoaderAware
- See Also:
 
- 
getExpressionResolves the given key in the retrieved bundle files to an Expression.- Specified by:
- getExpressionin interface- ExpressionSource
 
- 
clearCachepublic void clearCache()Clear the resource bundle cache. Subsequent resolve calls will lead to reloading of the properties files.
- 
toString
 
-