java config getlist,Java Config.getStringList方法代码示例

import com.typesafe.config.Config; //导入方法依赖的package包/类

public static void main(String[] args) {

// {{start:resource}}

Config defaultConfig = ConfigFactory.parseResources("defaults.conf");

// {{end:resource}}

// {{start:fallback}}

Config fallbackConfig = ConfigFactory.parseResources("overrides.conf")

.withFallback(defaultConfig)

.resolve();

// {{end:fallback}}

// {{start:text}}

log.info("name: {}", defaultConfig.getString("conf.name"));

log.info("name: {}", fallbackConfig.getString("conf.name"));

log.info("title: {}", defaultConfig.getString("conf.title"));

log.info("title: {}", fallbackConfig.getString("conf.title"));

// {{end:text}}

// {{start:resolved}}

log.info("combined: {}", fallbackConfig.getString("conf.combined"));

// {{end:resolved}}

// {{start:durations}}

log.info("redis.ttl minutes: {}", fallbackConfig.getDuration("redis.ttl", TimeUnit.MINUTES));

log.info("redis.ttl seconds: {}", fallbackConfig.getDuration("redis.ttl", TimeUnit.SECONDS));

// {{end:durations}}

// {{start:memorySize}}

// Any path in the configuration can be treated as a separate Config object.

Config uploadService = fallbackConfig.getConfig("uploadService");

log.info("maxChunkSize bytes: {}", uploadService.getMemorySize("maxChunkSize").toBytes());

log.info("maxFileSize bytes: {}", uploadService.getMemorySize("maxFileSize").toBytes());

// {{end:memorySize}}

// {{start:whitelist}}

List whiteList = fallbackConfig.getIntList("conf.nested.whitelistIds");

log.info("whitelist: {}", whiteList);

List whiteListStrings = fallbackConfig.getStringList("conf.nested.whitelistIds");

log.info("whitelist as Strings: {}", whiteListStrings);

// {{end:whitelist}}

// {{start:booleans}}

log.info("yes: {}", fallbackConfig.getBoolean("featureFlags.featureA"));

log.info("true: {}", fallbackConfig.getBoolean("featureFlags.featureB"));

// {{end:booleans}}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值