Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically change application.properties values in spring boot

Currently i am working on a REST based project in Spring Boot. I have added the api url in 'application.properties' file.

i.e.

application.properties

api-base-url=http://localhost:8080/RestServices/v1

And also this 'api-base-url' value access from java.

In some situations i need to change the 'api-base-url' dynamically. I have change 'api-base-url' value dynamically & working fine.

But my problem is that when wildfly restart then the configuration will be reset to default.

i.e This is my default value

api-base-url=http://localhost:8080/RestServices/v1

dynamically change to

api-base-url=http://10.34.2.3:8080/RestServices/v1

when wildfly restart then the configuration will be reset to default. i.e.

api-base-url=http://localhost:8080/RestServices/v1

Have any solution for this?

like image 777
Pamba Avatar asked Oct 31 '25 07:10

Pamba


1 Answers

You might want to consider using a cloud config server to host your config. Two examples are Spring Cloud Config and Consul.

These servers will host your application's configuration and your spring boot application will make a call out to the config server on start up to get it's config.

spring-boot-actuator exposes the endpoint /refresh which forces the application to refresh it's configuration. In this case, it will call out to the config server to get the latest version.

This way you can change the config hosted in the config server then hit the /refresh endpoint and the changes will be picked up by your application.

like image 117
Michael McFadyen Avatar answered Nov 02 '25 21:11

Michael McFadyen