TypeSafe Config使用
================typesafeconfig的使用====================
#1、加入依赖包 config-1.2.1.jar
#2、加载配置
ConfigFactory.parseFile(new File("resource/test.conf"));
ConfigFactory.load(test)
#3、getString(key)方法获取
config1.getString("complex-app.something")
// ConfigFactory.parseString使用parseString直接解析
Config config2 = ConfigFactory.parseString("akka.loggers = \"akka.testkit.TestEventListener\"");
System.out.println(config2.getString("akka.loggers"));
// 使用parseString 直接解析json字符串
Config config3 = ConfigFactory.parseString("{\"a\":\"b\", \"c\":\"d\"}");
System.out.println(config3.getString("a"));
System.out.println(config3.getString("c"));
#4、合并配置文件
Config firstConfig = ConfigFactory.parseFile(new File("resource/test.conf"));
Config secondConfig =ConfigFactory.parseFile(new File("resource/test1.conf"));
//a.withFallback(b) a和b合并,如果有相同的key,以a为准
Config finalConfig = firstConfig.withFallback(secondConfig);