Manoj Dubey
Manoj Dubey

Reputation: 43

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.

Upvotes: 0

Views: 1525

Answers (1)

PaulNUK
PaulNUK

Reputation: 5209

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.

Upvotes: 1

Related Questions