Q:

Spring boot add runtime property

I am looking for a solution where spring boot recreate new datasource when DB password is changed without restart.
spring.datasource.url=url
spring.datasource.username=usr
spring.datasource.password=passwordexampleno code
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
I have define datasource like this. What is best way to achieve this.

A:

There's a good blog on how to do this sort of thing here https://spring.io/guides/gs/centralized-configuration/
Basically you annotate your method that returns the datasource with @RefreshScope, change the configuration values in your externalised configuration (Spring Cloud Config server) and then trigger a refresh event for your application by calling the refresh endpoint exposed by Spring Boot actuator. 

