I\'m new to Spring and am attempting to use it\'s ReloadableResourceBundleMessageSource class.
I\'m attempting to use it so that we no longer have to restart our web
You are on the right path of extending ReloadableResourceBundleMessageSource
. As @JamesC mentioned, and per Spring's API documentation for ReloadableResourceBundleMessageSource
:
Since application servers typically 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).
I had a similar requirement as you. The key to solving it is extending ReloadableResourceBundleMessageSource
and overriding the calculateAllFilenames(String basename, Locale locale)
method to do more than appending language codes to the basename.
For example, if I have all my external message properties files under /srv/myapp/messages
(in the filesystem, NOT classpath), the overridden method would do something like:
@Override
protected List<String> calculateAllFilenames(final String basename,
final Locale locale) {
return super.calculateAllFilenames("file:///srv/myapp/messages/" + basename,
locale);
}
In my case, my list of basenames
are static and thus, I did not have to override other methods that calls calculateAllFilenames()
for each base name.
In your specific case, I would use Company
as the base name and override calculateAllFilenames()
to scan a directory outside of your classpath to resolve actual basenames and then call super.calculateAllFilenames()
for each resolved basename (i.e. super.calculateAllFilenames("file:///path/to/CompanyOneMessages", locale)
). Potentially, something similar to https://stackoverflow.com/a/11223178/1034436 would help. Note: unlike the referenced answer, I would not do the directory scan as part of a property setter if the resolved list of base names can change dynamically. Of course, performance considerations for your app will also need to be weighed in as it would obviously drastically increase filesystem access.
ReloadableResourceBundleMessageSource
requires the files to be under the webapp/ directory, not in your classpath (it can't reload those).