typesafe config 读取配置
所属分类 play
浏览量 728
Typesafe Config库,纯Java 零外部依赖
支持Java properties、JSON、JSON超集格式 HOCON 以及 环境变量
是 play Akka的配置管理库
HOCON(Human-Optimized Config Object Notation)
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
// 读取 application.conf
Config conf = ConfigFactory.load();
System.out.println(conf);
Config config = conf.getConfig("os");
System.out.println(config);
// os has type OBJECT rather than STRING
// System.out.println(conf.getString("os"));
System.out.println(conf.getString("os.name"));
System.out.println(conf.getString("name1"));
System.out.println(conf.getString("name2"));
System.out.println(conf.getString("server.ip"));
System.out.println(conf.getString("server.port"));
System.out.println(conf.getString("key1"));
System.out.println(conf.getString("key2"));
application.conf
conf1.conf
conf2.conf
application.conf
include "conf1.conf"
include "conf2"
#
targetServer=127.0.0.1
server{
ip=${targetServer}
port=8888
}
key1:value1
key2=value2
conf1.conf
name1=name1-value
conf2.conf
name2=name2-value
完整例子代码
https://gitee.com/dyyx/hellocode/tree/master/demo/typesafeConfigDemo
上一篇
下一篇
Scala并发之 Future ExecutionContext
scala type 关键字
Scala 抽象类(abstract) 和 特质(trait) 异同
对象存储简介
scala那些事
saas财务指标 ARR 与 MRR