【问题标题】:Typesafe Config: How to Create Conditional Configurations类型安全配置:如何创建条件配置
【发布时间】:2015-10-09 03:10:56
【问题描述】:

Typesafe Config 是否允许创建条件配置?

我需要根据另一个键的值来设置一个键:

ssl = true

#if ssl == true
host = "https://localhost"
#else
host = "http://localhost"
#end if

当然上面的代码不起作用......我只是想说明我正在尝试做的事情。

【问题讨论】:

    标签: typesafe-config


    【解决方案1】:

    不直接,不。对于您给出的特定示例,您可以使用可选属性:

    protocol = "http"
    protocol = ${?MY_PROTOCOL}
    
    host = ${protocol}://localhost
    

    然后,如果您的应用程序以 -Dprotocol=https 作为 java 的参数或以 MY_PROTOCOL=https 作为环境变量启动,您将在主机中获得 https。

    【讨论】:

      猜你喜欢
      • 2020-05-03
      • 1970-01-01
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-17
      • 1970-01-01
      • 2017-03-29
      相关资源
      最近更新 更多