我在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中查找类似的键时它不会失败。
答案 0 :(得分: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)