How to change initial parameters at runtime?

If I modify XML to change the value of the init parameter, I only see changes when redistributing the web application.

My question is impossible, I will get around this by setting values ​​at runtime. Is there any API that allows me to dynamically change values.

+4
source share
3 answers

He called init-parameter for some reason. So you cannot.

But you can change the values ​​at runtime, which is not a problem.

  • After reading the init parameters, put them as ServletContext attributes ( ctx.setAttribute("name", value) )
  • Create a small (password protected) page that lists all the attributes of the ServletContext and gives you the opportunity to change them.
+8
source

Perhaps you could use the apache commons configuration , in particular, see Automatic reload ...

+2
source

Instead, use the properties files and write the code so that 1) it reads the value from it each time or 2) it could reload the value by command or 3) it automatically reloads the file at certain intervals.

If you put the properties file somewhere in the path to the webapp runtime classes or add its path to the path to the webapp runtime path, 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"); 
+2
source

All Articles