Akka系列之Configration

概述

akka 使用 Typesafe Config Library来实现Configration, 同样地可以在自己的应用使用这个jar. maven地址

<dependency>
    <groupId>com.typesafe</groupId>
    <artifactId>config</artifactId>
    <version>1.3.1</version>
</dependency>

示例

在resources添加配置文件application.conf

simple-app {
	answer = 42
}

simple-lib.foo = "this is a test"
simple-lib.whatever = "i'm whatever"

代码

import com.typesafe.config.ConfigFactory

Config conf = ConfigFactory.load();
System.out.println("The foo is :" + conf.getString("simple-lib.foo"));

注: ConfigFactory默认会去寻找application.xx的文件作为配置

读取其他文件名配置

app2.conf

simple-lib.con = "Yes!"

simple-lib {
	how = 77
}
// 文件名省略后辍
Config conf1 = ConfigFactory.load("app2");
System.out.println("The con is :" + conf1.getString("simple-lib.con"));
System.out.println("how is : " + conf1.getInt("simple-lib.how"));

支持json格式

app3.json

{
"root" : "root~~",
"name" : 22
}
Config conf2 = ConfigFactory.load("app3");
System.out.println("read json file. root:" + conf2.getString("root"));
System.out.println("read json file. name:" + conf2.getString("name"));

转载于:https://my.oschina.net/u/1159959/blog/1456961

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值