Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maintain, update application properties dynamically in Spring? [duplicate]

I would like to maintain a list of application properties like service endpoints, application variables, etc. in a Spring application. These properties should be able to updated dynamically (possibly through an web page by system administrator).

Does spring has an inbuilt feature to accomplish this requirement?

like image 663
Vel Avatar asked Dec 16 '16 20:12

Vel


1 Answers

I am not sure spring has an implementation for updating the properties file dynamically.

You can do something like reading the properties file using FileInputStream into a Properties object. Then you will be able to update the properties. Later you can write back the properties to the same file using the FileOutputStream.

// reading the existing properties
FileInputStream in = new FileInputStream("propertiesFile");
Properties props = new Properties();
props.load(in);
in.close();
// writing back the properties after updation
FileOutputStream out = new FileOutputStream("propertiesFile");
props.setProperty("property", "value");
props.store(out, null);
out.close();
like image 57
Johny Avatar answered Oct 29 '22 13:10

Johny