How to re-load properties files without restarting server in java

Re-load properties files without restarting server in Java:

Restart an application-server (servlet-container) means restart all the web-apps that are running under that application-server, with resulting unavailability of services. For this we’ll use the Java class PropertiesConfiguration available in the Apache Common Configuration library. This class allow to bind properties file to a PropertiesConfiguration Java Object through which read the single properties.
Using Apache Commons Configuration to resolve this issue,

PropertiesConfiguration propertiesConfig = new PropertiesConfiguration("yourProps.properties");
propertiesConfig.setReloadingStrategy(new FileChangedReloadingStrategy());

For this need to use commons-configuration dependency / jar.

<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>20041012.002804</version>
</dependency>
you can find further details in the java-doc, This will Re-load properties files without restarting server.
image logo

No comments :

Post a Comment