0

I have a properties file in spring-boot app which has postgres instance details for both the database hosted in AWS and one in local. Every time I checkout the code from git I have to comment the postgres AWS entries and uncomment the local postgres instance to work locally. Again when I want to checkin, I have to do the opposite. What is the smartest way to handle this configuration switching so that I don't have to do this every time.

N.B.: AWS deployment happens from github via Jenkins pipeline

sromit
  • 900
  • 3
  • 16
  • 43

2 Answers2

1

You should provide your database parameters as environment variables in your IDE in the project setting (for example). Then set them in your application.properties as placeholders. For example:

spring.datasource.url=${DATASOURCE_URL}

Where DATASOURCE_URL is one of the env. variable.

So at your work you set your local parameters, and on AWS you set prod parameters.

Cepr0
  • 28,144
  • 8
  • 75
  • 101
0
  • use environment variables - you can use your local settings as default values and set environment variables for AWS usage on your EC2 instance
  • use profiles and set active profile using command line parameter or environment variable on EC2 instance

Read more about: - externalised configuration in Spring Boot - Spring Profiles

Maciej Walkowiak
  • 12,372
  • 59
  • 63