Typesafe/Hocon配置:变量替换:参考路径

vvg*_*vvg 13 scala typesafe typesafe-config

我们有一个项目,其中包含使用hocon配置构建的大型配置文件.有意在可能的情况下使用变量来创建template_section,并根据某些选项在模板中设置一些值.

问题是variables在这个配置中使用时,我必须始终引用绝对路径.有可能以某种方式使用规范名称(如果属性位于同一级别)?

例:

foo {
    bar = 4
    baz = ${foo.bar} // work perfect
    baz = ${[this].bar} // can I do smth like that? Any ideas.
}
Run Code Online (Sandbox Code Playgroud)

更真实的例子.我实际上正在寻找的是建立hocon配置的一般OOP能力.我有一些父配置template_configimportant_option内部真正取决于实现: custom_config1或者custom_config2,我有什么现在做的是落实important_option在儿童的配置,因为绝对pathes我不得不提及自定义配置sectsions名.

custom_config1: $template_config {
    child_option = child_value1
}

custom_config2: $template_config {
    child_option = child_value2
}

template_config {
    important_option = ${child_option} // NOT POSSIBLE
    child_option = not_implemented
}
Run Code Online (Sandbox Code Playgroud)

Dae*_*yth 2

遗憾的是,baz = ${[this].bar}HOCON 不支持您假设的路径自引用(截至 2022 年)