2017-12-18 75 views
0

我有以下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中查找類似的鍵時不會失敗。

回答

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) 
+0

完美。謝謝。 – horatio1701d