English 中文(简体)
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.

最佳回答

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.)

问题回答

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.

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.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签