开发者

How to Change init-parameters at Runtime?

If I modify 开发者_运维技巧the XML to change the value of init parameter I see the changes only when web-app is redeployed.

My question is cant I get around this by setting the values at run time.Is there any API that allow me to change the values dynamically.


It's called init-parameter for a reason. So, you can't.

But you can change values at runtime, that's no problem.

  1. After reading the init parameters put them as attributes of the ServletContext (ctx.setAttribute("name", value))
  2. Create a small (password-protected) page that lists all attributes of the ServletContext and gives the ability to change them.


Maybe you could use apache commons configuration, specifically have a look at Automatic Reloading...


Make use of properties files instead and write code so that it 1) reads the value from it everytime, or 2) can reload the value on command, or 3) reloads the file automatically at certain intervals.

If you put the properties file somewhere in the webapp's runtime classpath or add its path to the webapp's runtime classpath, then you can easily access/load it as follows:

Properties properties = new Properties();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("filename.properties"));
String value = properties.get("key");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜