paulgreg
paulgreg

Reputation: 18903

In Java, how to reload dynamically resources bundles in a web application?

We are using fmt:setBundle to load a resource bundle from a database (we extended the ResourceBundle class to do that). When we modify a value in database, we have to reload the web server to display the new value on the web app.

Is there any simple way to use the new value without restarting the web server ?

(We do not want to always look up the value from database but we would like to invalidate the cache, for example by calling a special 'admin' URL)

EDIT : We are using JDK 1.4, so I would prefer a solution on that version. :)

Upvotes: 8

Views: 8719

Answers (3)

y.hussain
y.hussain

Reputation: 19

First you can create a class which extends from ReloadableResourceBundleMessageSource to expose its inner class protected method called getProperties. This method return a concurrent map from PropertiesHolder object. Second you should configure a bean of that extended class in you web configuration class. Now you able to use messageSource in your service or business layer. Here is the reference link Configure reloadable message source bundle

Upvotes: 1

user7094
user7094

Reputation:

As others have pointed out in the comments, you might want to look into Spring - particularly the ReloadableResourceBundleMessageSource.

Upvotes: 3

WMR
WMR

Reputation: 12971

If you're using JDK 1.6 you can use the callback methods getTimeToLive() and needsReload() in ResourceBundle.Control to control if the bundle cache needs to be loaded with new values from the database.

Upvotes: 7

Related Questions