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?
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 aProperties
object. Then you will be able to update the properties. Later you can write back the properties to the same file using theFileOutputStream
.Externalizing properties, take a look here
Spring loads these properties which can be configured at runtime and accessed in your application in different ways.
I am not sure, but check if you can make use @ConfigurationProperties of Spring boot framework.
Java Experts - I am just trying to explore my view. Corrections are always welcome.
Edit - I read a good examples on @PropertySource here
Add your own implementation of a
PropertySource
to yourEnvironment
.Warning: Properties used by
@ConfigurationProperties
and@Value
annotations are only read once on application startup, so changing the actual property values at runtime will have no effect (until restarted).