Load properties file

I have a web application that reads content from a properties file. When this properties file is loaded into memory. i.e. As soon as I deploy my app with some content in the prop file and after deploying, I change the content of the prop file, will the changes show up or do I need to redistribute?

EDIT: The static block of the accessor class reads the content from the properties file, which is part of the deployed web application. Now after deploying, I change the contents of the properties file. Will the accessor class read the changes or will it accept the old values?

EDIT2: When the class is reloaded it will most likely take over a new modified file, or rather take over a file cached during deployment (if it is cached at all)

+2


source to share


4 answers


Assuming the property file is loaded by the Properties class, then the property file will be loaded once when the Properties # load () method is called. It will not automatically reload if your application does not support reloading or if your web container restarts the web application during hot deploy.



update: since the properties file is loaded into a static initializer, then the property file will be reloaded when the class is reloaded (for example, when the web application is hot deployed). If you want to debug this, a simple println () example in a static initializer will show you when this happens.

+2


source


It depends on the application server - usually you will have to redistribute. However, some application servers, in certain configurations, can monitor files and trigger redeployments when they detect file changes. (As an example - I believe Tomcat will automatically redeploy when it detects file changes in exploded deployments.)



+1


source


If this file is loaded by your class, I am sure it will not reload it itself.

If I were you, I would have a separate thread that wakes up at specified intervals, checks if the file modification date has changed, and if it did, then reload it.

0


source


Apache Commons config provides automatic reload / save of configurations based on files.

0


source







All Articles