2

I am trying to develop a microservice by using sprin and spring boot with postgresql database. I am here using distributted datbase. So for particular region I am using one DB, and for other region I am using different DB. Currently I only tried with one database. I added datasource name , username and password in application.properties.

Here my doubt is that, if I am using multiple distributed database, how cam mention different DB source URL in configuration (application.properties)? I am using following structure to use one database currently,

spring.datasource.url=jdbc:postgresql://localhost/milleTech_users spring.datasource.username=postgres spring.datasource.password=postgresql spring.jpa.generate-ddl=true 

Like above.

So if I am using multiple DB for multiple region How I can give configuration conditionally here? I am new to microservice world and distributed database design pattern.

1 Answer 1

3

Multiple Database details cannot be managed within a single application.properties.

Consider using Spring Cloud Config where in you can create multiple application.properties with different profile names for every application.

In your case, the profile names could reflect the region. When you deploy to a particular region, launch the app with that profile name so that the required config would be loaded and appropriate database connection would be used

Edit :

Also in your case, if you can set environment variables, you can explore on the following option mentioned in this thread

Sign up to request clarification or add additional context in comments.

11 Comments

Ok I understood. Is there any documentation that you can share for implementing multiple application.properties using spring cloud as you mentioned in your answer?
here you go baeldung.com/spring-cloud-configuration . Pls accept if the answer is useful !
Ok. Will check this link. Thank you for your response.
The property file that you are creating in the Spring Cloud Server is going to be replaced at the client when the App initializes. To understand this, you can copy over your current application.property file, change few values and place it in the Cloud Config Server. When the app initializes, you will see the new values
java -jar -Dspring.profiles.active=<<ProfileName>> application.jar . for more options refer stackoverflow.com/questions/31038250/…
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.