How to use spring boot profiles

What are profiles

Every entrepreneur application follows environments. like DEV, QA, UAT, PREPROD and PROD. and every environment has their own db, port and other configurations.

How do we maintain profiles in spring boot application

while we creating springboot application using https://start.spring.io/ it will provide property file named as application.properties inside src/main/resources folder.

Next we have to make property file for each environment. and we should active them in application level using spring provided command.

Have to create environment files like below inside src/main/resources folder:

  1. application-dev.properties
  2. application-qa.properties
  3. application-prod.properties

application.properties file will be act as a master file. and remain files will be act as a slave which has extension of .properties.

one last setting is how to let the system know that this is DEV, QA and PROD. we can do like this. In application.properties file we have to provide key. spring.profiles.active=dev

springboot application will run using dev profile. we can check on which profile our application has run using application logs. like below.

2021-09-14 10:58:15 [main] INFO c.f.m.MessagingQueueApplication - The following profiles are active: dev