Spring Cloud Config Server Priority of Environment Variables

淺唱寂寞╮ 提交于 2019-12-04 08:52:00

问题


I have a question regarding the priority of environment variables when working with spring cloud config server

In my service I have a local properties file application.yml with this content

foo:
  bar: "some"
  buz: "some"
  joe: "some"

The service is also connected to a config server with a configuration repository that contains a file testservice-api.yml (where testservice-api is the spring application name of the service). The contents of this file is:

foo:
  bar: "some-specific"

So with this setup the configuration at runtime would result in this:

{
    "foo.bar": "some-specific",
    "foo.buz": "some",
    "foo.joe": "some"
}

Now I try to override foo.bar and foo.joe with an environment variable.

So I start the service with this command:

FOO_BAR=some-env FOO_JOE=some-env gradle bootRun

From what I read in this part of the spring boot documentation the environment variables should have priority over the configuration files - also the spring cloud config documentation does not state sth different - so I would expect the result to be:

{
    "foo.bar": "some-env",
    "foo.buz": "some",
    "foo.joe": "some-env"
}

But instead I get:

{
    "foo.bar": "some-specific",
    "foo.buz": "some",
    "foo.joe": "some-env"
}

So only the configuration from the local configuration file inside the jar is overridden by the environment variable - the property from the config repo seems to have priority over the environment variable.

Is this explainable - Or is this a bug? Any hints in this one?

Please find the example code here:

https://github.com/mduesterhoeft/configserver-test

The README in the repository lists the issue described here as Use Case 3


回答1:


define following properties in git repo (as a source for config-server) [for given profile]: spring.cloud.config: overrideSystemProperties: false overrideNone: true

keep in mind properties (especially overrideSystemProperties & overrideNone) in bootsrap.yml are overriden by those from config-server by default



来源:https://stackoverflow.com/questions/37316835/spring-cloud-config-server-priority-of-environment-variables

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