jthg
jthg

Reputation: 2850

Where should I put this configuration setting?

I'm designing a fairly small web application which will run on a Sun application server (v9.1). It only has a few pages, no database of its own, and will retrieve/update data via web services. There's one block of text on one of the pages which we anticipate will need to be updated occasionally (a few times a year?) by a system admin. What's the best way to allow updating of that block of text?

I don't think modifying the web service to provide the text is a viable option. It would also be nice if we didn't have to reWAR the web app in order to do the update.

Upvotes: 2

Views: 426

Answers (3)

BalusC
BalusC

Reputation: 1108732

You can keep it in propeties file format and use java.util.ResourceBundle to get the values from it. This way you can use ResourceBundle#clearCache() or provide a custom ResourceBundle#Control to control the cache.

Upvotes: 0

Pascal Thivent
Pascal Thivent

Reputation: 570365

If using a properties file is an option, you could use Commons Configuration to load it from the classpath (so it could be outside the WAR) and use the automatic reloading feature to reload it in case of changes.

(EDIT: To answer a comment about Commons Configuration, I agree that it might not be the best piece of code of Apache but I can't say that I find this to be a nightmare:

PropertiesConfiguration config = new PropertiesConfiguration("usergui.properties");
config.setReloadingStrategy(new FileChangedReloadingStrategy());

Using properties might not be ideal but, well, for a block of HTML, it should do the trick.)

Upvotes: 4

Carl Smotricz
Carl Smotricz

Reputation: 67760

Having re-read your question:

If the text is the only property that needs changing, then a property file is not the right solution. And we're in a servlet environment, and you change it but rarely.

I think the text should be read (via the usual file I/O methods) from a plaintext file into the ServletContext by a lifecycle listener. If you want to change the text, take an editor to it, then quickly restart just that servlet, and you're done. The app can refer to the (single) in-memory copy that your listener puts into the context, it runs quickly and it's easy to change.

Upvotes: 0

Related Questions