Skip to content

5. 多数据源支持与覆盖

王宇轩 edited this page Oct 21, 2016 · 2 revisions

多数据源支持

load properties from zookeeper

ZookeeperConfigProfile configProfile = new ZookeeperConfigProfile("zoo.host1:8181", "/projectx/modulex", "1.0.0");
GeneralConfigGroup propertyGroup1 = new ZookeeperConfigGroup(configProfile, "property-group1");

load properties from classpath file

FileConfigProfile configProfile = new FileConfigProfile("UTF8", "properties");
ConfigGroup configGroup = new FileConfigGroup(configProfile, "classpath:property-group1.properties");

load xml properties from classpath file

FileConfigProfile configProfile = new FileConfigProfile("UTF8", "xml");
ConfigGroup configGroup = new FileConfigGroup(configProfile, "classpath:property-group1.xml");

load properties from file

FileConfigProfile configProfile = new FileConfigProfile("UTF8", "properties");
ConfigGroup configGroup = new FileConfigGroup(configProfile, "file:/Users/yuxuanwang/Work/git/config-toolkit/config-toolkit-demo/src/main/resources/property-group1.properties");

load properties from http

FileConfigProfile configProfile = new FileConfigProfile("UTF8", "properties");
ConfigGroup configGroup = new FileConfigGroup(configProfile, "http://crnlmchina.github.io/config-group.properties");

配置覆盖

不同的配置组之间可以任意互相覆盖.

[例]通过本地配置文件覆盖zookeeper配置:

ZookeeperConfigProfile configProfile = new ZookeeperConfigProfile("zoo.host1:8181", "/projectx/modulex", "1.0.0");
ConfigGroup zkConfigGroup = new ZookeeperConfigGroup(configProfile , "property-group1");
FileConfigProfile fileConfigProfile = new FileConfigProfile("UTF8", "properties");
ConfigGroup configGroup = new FileConfigGroup(zkConfigGroup, fileConfigProfile, "classpath:config-group1.properties");