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: 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.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.


I had to add this:

bootRun {
    String activeProfile =['']
    String confLoc =['spring.config.location']
    systemProperty "", activeProfile
    systemProperty "spring.config.location", "file:$confLoc"

And now bootRun picks up the profile and config locations.

Thanks a lot @jst for the pointer.

Answered By – O-OF-N

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published