HOCON替代默认值 [英] HOCON Substitution default value
本文介绍了HOCON替代默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在HOCON和Typesafe Config中,如何在替换时设置默认值.
In HOCON and Typesafe Config, How do I set the default value in case of substitution.
它支持这样的东西吗?
${server.host: 'localhost'}
->如果设置了server.host(在相同的配置文件中或通过环境设置),它将替换为如果未设置,则选择默认值
${server.host: 'localhost'}
-> If server.host set(Either in the same configu files or through environement setting) it substitutes that if not set choose the default value
推荐答案
摘自替换:
如果未定义用$ {?foo}语法的替换:
If a substitution with the ${?foo} syntax is undefined:
- 如果它是对象字段的值,则不应创建该字段.如果该字段将覆盖的先前设置的值 同一字段,则保留先前的值.
- if it is the value of an object field then the field should not be created. If the field would have overridden a previously-set value for the same field, then the previous value remains.
因此,这是使用对象合并:
defaults {
foo: "default Value"
}
item = ${defaults} {
foo: ${?bar}
}
或更简单:
item = {
foo: "default Value"
foo: ${?bar}
}
这篇关于HOCON替代默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文