以前我简单介绍过dremio 关于typesafe config 的使用说明,还是比较强大的,以下是一个简单的学习使用
项目配置
参考图
内容
application.conf 会引用defaultvalues.conf,dremio 会自动帮助我们处理
application.conf
include classpath("defaultvalues.conf")
service {
com.dalong.app = 11
com.classpath += "dalongdemoapp"
com.classpath += "demoapp"
userlogintype: "default"
}
dremio {
com.scanpath:"dalongdemo",
myage: ${service.com.dalong.app}
}
defaultvalues.conf
login {
type:"default"
}
service {
com.dalong.app = 222
com.classpath += "dalongdemoapp"
com.classpath += "demoapp"
userlogintype: "default"
platformpath:"demo.com"
}
代码访问
public static void main(String[] args) {
Config config = ConfigFactory.load();
int age = config.getInt("service.com.dalong.app");
List<String> classpaths = config.getStringList("service.com.classpath");
String loginType = config.getString("service.userlogintype");
int newAge = config.getInt("dremio.myage");
System.out.println(age);
System.out.println(classpaths);
System.out.println(loginType);
System.out.println(newAge);
}
说明
基于typesafe config 进行项目的配置是一个不错的选择,还是很强大的,而且很灵活,具体格式可以参考官方文档
参考资料
https://github.com/lightbend/config
https://github.com/lightbend/config/blob/main/HOCON.md