【问题标题】:duplicate application.conf in typesafe config projects在类型安全配置项目中重复 application.conf
【发布时间】:2016-09-16 04:27:49
【问题描述】:

我正在阅读一些代码,它使用类型安全配置来读取资源文件夹中的application.conf 文件。我正在使用一个在其资源文件夹中有一个 application.conf 的库,我从另一个项目中调用这个库,该项目在其资源文件夹中有自己的 application.conf

typesafe config 能否分别读取正确的配置文件?

【问题讨论】:

    标签: scala typesafe-config


    【解决方案1】:

    来自文档:

    The substitution syntax ${foo.bar} will be resolved twice. First, all the reference.conf files are merged and then the result gets resolved. Second, all the application.conf are layered over the reference.conf and the result of that gets resolved again.

    因此,两个库将看到相同的 Config,这是合并两个 application.conf 的结果(假设两者都使用默认行为并且类路径上没有更多的 application.confreference.conf 文件)。每个库应该不只是将其配置放在根目录中,而是拥有自己的配置树部分:即不

    debug = true
    server = "example.com"
    

    但是

    my.cool.library {
      debug = true
      server = "example.com"
    }
    

    如果遵循此规则,库将不会发生冲突。如果他们使用不同含义的相同路径,您将遇到麻烦。

    【讨论】:

      猜你喜欢
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-31
      • 2016-10-15
      • 2018-10-31
      • 2014-04-27
      • 2013-09-17
      相关资源
      最近更新 更多