简体   繁体   English

如何将一组值作为环境变量提供给 typesafe/lightbend 配置?

[英]How to provide an array of values as an env variable to typesafe/lightbend config?

How do I provide an array/list of values as an environment variable to typesafe/lightbend config?如何将数组/值列表作为环境变量提供给 typesafe/lightbend 配置?

application.conf

default-buckets = [
      10,
      30,
      100,
      300,
      1000,
      3000,
      10000,
      30000,
      100000
    ]
default-buckets = [${?DEFAULT_BUCKETS}]

So, I'd like to pass something like this as an environment variable to be able to override the defaults:所以,我想将这样的东西作为环境变量传递,以便能够覆盖默认值:

DEFAULT_BUCKETS=1000,3000

However, I'm getting the following error:但是,我收到以下错误:

com.typesafe.config.ConfigException$WrongType: env variables: buckets.default-buckets has type list of STRING rather than list of NUMBER

Is this possible without having to have my application code deal with it by eg calling split(',') ?这是可能的,而不必让我的应用程序代码通过例如调用split(',')处理它吗?

As far as I'm aware, there's no simple way to pass a list of environment variable to override an array of conf values.据我所知,没有简单的方法可以传递环境变量列表来覆盖 conf 值数组。

You will have to set env vars like so:您必须像这样设置环境变量:

export DEFAULT_BUCKETS_1=1000
export DEFAULT_BUCKETS_2=3000

Then pass them into the conf file:然后将它们传递到 conf 文件中:

default-buckets = []
default-buckets.0 = ${?DEFAULT_BUCKETS_1}
default-buckets.1 = ${?DEFAULT_BUCKETS_2}
default-buckets = [
  ${?DEFAULT_BUCKETS_1},
  ${?DEFAULT_BUCKETS_2},
  ${?DEFAULT_BUCKETS_3},
  ${?DEFAULT_BUCKETS_4},
  ${?DEFAULT_BUCKETS_5}
]

For为了

DEFAULT_BUCKETS_1=10
DEFAULT_BUCKETS_2=30
DEFAULT_BUCKETS_5=100

Results in结果是

TestConfig(List(10, 30, 100))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM