0

我在 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 中查找类似键时不会失败。

4

1 回答 1

3

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

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)
于 2017-12-18T13:29:13.923 回答