Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

springboot external configuration - profile specific configuration

According to the SpringBoot documentation, the order of configuration is as:

Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)

Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants)

Application properties outside of your packaged jar (application.properties and YAML variants).

Application properties packaged inside your jar (application.properties and YAML variants).

On my project I have a profile called "prod" and the following files:

  • application.yml (inside the jar)
  • application-prod.yml (inside the jar)

And I also want to override some of the properties using an external file. Since according to the docs, an external application.yml will be overridden by the internal application-prod.yml, I need to make sure that the external file is considered as a profile specific config file.

I have tried to use:

-Dspring.config.location=<my path>/application-prod.yml

and I have also tried:

-Dspring.config.location=file:<my path>/application-prod.yml

In all cases I get the value from the internal application-prod.yml

If I totally remove the internal config file then I get the value from the external (so I know that the config picks up the file).

I understand that this external file is considered as the equivalent to the generic application.yml and not a profile specific.

How can I configure it to be considered as a profile specific external config?

like image 851
Panos Avatar asked Oct 20 '25 19:10

Panos


1 Answers

Found the answer:

You need to use a Directory externally to set the profile specific configuration files, not using the file directly and it needs to end in /. So it has to be:

-Dspring.profiles.active=prod

-Dspring.config.location=/<some-path>/config/ (any path that ends in /)

and in there have a :

application-prod.yml

like image 105
Panos Avatar answered Oct 23 '25 09:10

Panos