【问题标题】:Processing Environment Variables in Typesafe Config在 Typesafe Config 中处理环境变量
【发布时间】:2019-04-02 15:08:14
【问题描述】:

我有一个 Typesafe 配置文件 (application.conf)。我想用系统环境变量覆盖一些设置(比如Overriding configuration with environment variables in typesafe config),但是我想对环境变量中的值做一些修改(例如toLowerCase,replace('\','/'),split ("/"))

所以我有这样的事情:

# C:\Users\...\project_root\sub_project\src\main\resources\application.conf

foo = {
  bar = "baz"
}

我把它改成这样:

foo = {
  bar = "baz"
  bar = ${?FOO}
}

但现在我想这样做:

foo = {
  bar = "baz"
  bar = ${?FOO.toLowerCase}
}

当我在我的项目上运行 sbt update 时,我拥有的 Typesafe Config 依赖项是这样的:

[info] Resolving com.typesafe#config;1.2.1 ...

【问题讨论】:

标签: scala sbt config typesafe-config


【解决方案1】:

而不是直接访问类型安全配置,您可能应该在项目的 util 模块中定义一个接口并通过该接口访问您的配置。这样你就有了一个集中的地方来获取你的配置,并且这个集中的地方可以在基本存储和获取配置值的基础上提供额外的功能。此外,您可以使用位于类型安全配置前面的库并通过该库访问值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-29
    • 2020-08-16
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多