在 HOCON 和 Typesafe Config 中,如何在替换的情况下设置默认值。
它支持这样的东西吗??
${server.host: 'localhost'}
-> 如果设置了 server.host(在相同的配置文件中或通过环境设置),它会替代,如果未设置,则选择默认值
最佳答案
来自 substitutions 上的官方文档:
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.
所以这是一种可能的解决方法,使用 object merging :
defaults {
foo: "default Value"
}
item = ${defaults} {
foo: ${?bar}
}
或者更简单:
item = {
foo: "default Value"
foo: ${?bar}
}
关于java - HOCON替换默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38822992/