springboot external configuration - profile specific configuration

ぃ、小莉子 提交于 2020-06-26 04:08:35

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/51186918/springboot-external-configuration-profile-specific-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!