Spring Cloud Config Server环境变量优先级 [英] Spring Cloud Config Server Priority of Environment Variables

查看:818
本文介绍了Spring Cloud Config Server环境变量优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 spring cloud配置服务器



在我的服务中,我有一个本地属性文件 application.yml with这个内容

  foo:
bar:some
buz:some
joe:some

该服务还连接到配置服务器,配置存储库包含file testservice-api.yml (其中 testservice-api 是服务的spring应用程序名称)。这个文件的内容是:

  foo:
bar:some-specific

因此,使用此设置,运行时的配置将导致:

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

现在我尝试覆盖 foo带有环境变量的.bar foo.joe



所以我用这个命令启动服务:



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



从我在这部分spring boot文档环境变量应该优先于配置文件 - spring cloud配置文档也没有说明不同 - 所以我希望结果是:

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

但我得到:

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

所以只有本地配置文件中的配置罐子里面是overri由环境变量dden - 来自config repo的属性似乎优先于环境变量。



这是否可解释 - 或者这是一个错误?这个中有任何提示吗?



请在此处找到示例代码:




$ b

存储库中的README将此处描述的问题列为用例3

解决方案

在git repo中定义以下属性(作为配置的来源)服务器)[对于给定的配置文件]:

spring.cloud.config:
overrideSystemProperties:false
overrideNone:true



请记住,bootsrap.yml中的属性(特别是overrideSystemProperties& overrideNone)默认覆盖来自config-server的属性


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

这篇关于Spring Cloud Config Server环境变量优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆