10

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

4

1 回答 1

9

在 git repo 中定义以下属性(作为配置服务器的源)[对于给定的配置文件]: spring.cloud.config: overrideSystemProperties: false overrideNone: true

请记住 bootsrap.yml 中的属性(尤其是 overrideSystemProperties 和 overrideNone)默认被 config-server 中的属性覆盖

于 2016-07-29T12:20:54.580 回答