【问题标题】:Pureconfig Typesafe Config with Hierarchical Root Keys带有分层根密钥的 Pureconfig 类型安全配置
【发布时间】:2017-12-18 12:38:17
【问题描述】:

我在 application.conf 中有以下内容,并试图找出定义我的类以加载配置的最佳方法:

allKeys {
   mysql {
     dev {
       host = <host1>
       user = <user1>
     }
     prod {
       host = <host1>
       user = <user1>
   }
   hdfs {
     endpoint = <host1>
     port = <port1>
   }
}

my case classes:
  case class Settings(mysql: DbSettings, hdfs: HdfsSettings)
  case class DbSettings(host: String, user: String)
  case class HdfsSettings(endpoint: String, port: String)

我不知道如何正确加载它,以便它在 hdfs 中查找类似键时不会失败。

【问题讨论】:

    标签: scala pureconfig


    【解决方案1】:

    您需要定义案例类以适应配置结构。

    case class HdfsConfig(endpoint: String, port: Int)
    case class DbConfig(host: String, user: String)
    case class MySqlConfig(dev: DbConfig, prod: DbConfig)
    case class AllConfigs(mysql: MySqlConfig, hdfs: HdfsConfig)
    
    case class MyConfig(allKeys: AllConfigs)
    

    现在您可以将这些理解为,

    loadConfig[MyConfig](conf)
    

    【讨论】:

      猜你喜欢
      • 2014-11-16
      • 2021-06-11
      • 2018-09-17
      • 1970-01-01
      • 2022-01-22
      • 2017-03-23
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      相关资源
      最近更新 更多