Setting active profile and config location from command line in spring boot

I have a spring boot application.

I have three profiles in my application-> development, staging and production. So I have 3 files

  1. application-development.yml
  2. application-staging.yml
  3. application-production.yml

My application.yml resides inside src/main/resources. I have set the active profile in application.yml as :

spring:
  profiles.active: development

The other 3 profile specific config files are present in C:\config folder.

I am using gradle plugin for eclipse. When I try to do a “bootRun“, I am setting the command line arguments in my gradle configuration in eclipse as

 -Dspring.profiles.active=staging -Dspring.config.location=C:\Config

However, the command line property is not getting reflected and my active profile is always getting set as development(which is the one that I have mentioned in the applications.yml file). Also C:\Config folder is not searched for profile specific config files.

I think I am missing something here. I have been trying to figure it out for the past 2 days. But no luck. I would really appreciate any help.

15 Answers
15

Leave a Comment