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