Pureconfig类型安全配置与层次的根密钥
我有以下application.conf并试图找出定义我的课班上最好的方式来加载配置:Pureconfig类型安全配置与层次的根密钥
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中查找类似的键时不会失败。
回答:
您需要定义您的案例类以适应配置结构。
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)
以上是 Pureconfig类型安全配置与层次的根密钥 的全部内容, 来源链接: utcz.com/qa/263384.html