[英]How reuse properties in typesafe config files?
Consider following files: 考虑以下文件:
application.conf application.conf
app {
port = 5000
}
reference.conf reference.conf
akka {
cluster {
seed-nodes = ["akka.tcp://sysName@localhost:"${app.port}]
}
}
So when I run ConfigFactory.load()
it fails, because ${app.port}
does not present in reference.conf. 因此,当我运行
ConfigFactory.load()
它将失败,因为${app.port}
未出现在reference.conf中。
But load algorithm is clear - reference.conf
is loaded and merged with application.conf
. 但是加载算法很明确
reference.conf
已加载并与application.conf
合并。 Is there a way to load application.conf
and "include" reference.conf
into it? 有没有一种方法可以将
application.conf
和“ include” reference.conf
加载到其中?
IMPORTANT 重要
I tried add include "reference.conf"
at the first line in application.conf
it does not help. 我试过在
application.conf
的第一行添加include "reference.conf"
并没有帮助。
You can use file("")
syntax to include file. 您可以使用
file("")
语法包含文件。
include file("reference.conf")
see https://github.com/typesafehub/config/blob/master/HOCON.md#include-syntax 参见https://github.com/typesafehub/config/blob/master/HOCON.md#include-syntax
According to Typesafe Config documentation : 根据Typesafe Config 文档 :
The implication of this is that the
reference.conf
stack has to be self-contained;这就意味着
reference.conf
堆栈必须是独立的。 you can't leave an undefined value${foo.bar}
to be provided byapplication.conf
, or refer to${foo.bar}
in a way that you want to allowapplication.conf
to override.您不能保留由
application.conf
提供的未定义值${foo.bar}
,或者以您希望允许application.conf
覆盖的方式引用${foo.bar}
。 However,application.conf
can refer to a${foo.bar}
inreference.conf
.但是,
application.conf
可以在reference.conf
中reference.conf
${foo.bar}
。
The documentation also lists some possible workarounds: 该文档还列出了一些可能的解决方法:
- putting an
application.conf
in a library jar, alongside thereference.conf
, with values intended for later resolution.将
application.conf
与reference.conf
一起放在库jar中,其值供以后解决。- putting some logic in code instead of building up values in the config itself.
在代码中添加一些逻辑,而不是在配置本身中建立值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.