Search in sources :

Example 1 with PropertiesLoader

use of io.servicecomb.foundation.common.config.impl.PropertiesLoader in project java-chassis by ServiceComb.

the class ConfigMgr method init.

public void init() throws Exception {
    List<Resource> resArr = PaaSResourceUtils.getSortedResources("classpath*:config/config.inc.xml", ".inc.xml");
    IncConfigs incConfigs = new IncConfigs();
    incConfigs.setPropertiesList(new ArrayList<>());
    incConfigs.setXmlList(new ArrayList<>());
    for (Resource resource : resArr) {
        IncConfigs tmp = XmlLoaderUtils.load(resource, IncConfigs.class);
        if (tmp.getPropertiesList() != null) {
            incConfigs.getPropertiesList().addAll(tmp.getPropertiesList());
        }
        if (tmp.getXmlList() != null) {
            incConfigs.getXmlList().addAll(tmp.getXmlList());
        }
    }
    configLoaderMap = new HashMap<>();
    for (IncConfig incConfig : incConfigs.getPropertiesList()) {
        PropertiesLoader loader = (PropertiesLoader) configLoaderMap.get(incConfig.getId());
        if (loader != null) {
            loader.getLocationPatternList().addAll(incConfig.getPathList());
            continue;
        }
        configLoaderMap.put(incConfig.getId(), new PropertiesLoader(incConfig.getPathList()));
    }
    for (IncConfig incConfig : incConfigs.getXmlList()) {
        XmlLoader loader = (XmlLoader) configLoaderMap.get(incConfig.getId());
        if (loader != null) {
            loader.getLocationPatternList().addAll(incConfig.getPathList());
            continue;
        }
        configLoaderMap.put(incConfig.getId(), new XmlLoader(incConfig.getPathList()));
    }
}
Also used : IncConfig(io.servicecomb.foundation.common.config.impl.IncConfigs.IncConfig) IncConfigs(io.servicecomb.foundation.common.config.impl.IncConfigs) Resource(org.springframework.core.io.Resource) XmlLoader(io.servicecomb.foundation.common.config.impl.XmlLoader) PropertiesLoader(io.servicecomb.foundation.common.config.impl.PropertiesLoader)

Example 2 with PropertiesLoader

use of io.servicecomb.foundation.common.config.impl.PropertiesLoader in project java-chassis by ServiceComb.

the class Log4jUtils method init.

public static void init(String locationPattern) throws Exception {
    if (inited) {
        return;
    }
    synchronized (LOCK) {
        if (inited) {
            return;
        }
        PropertiesLoader loader = new PropertiesLoader(Arrays.asList(locationPattern));
        Properties properties = loader.load();
        if (properties.isEmpty()) {
            throw new Exception("can not find resource " + locationPattern);
        }
        PropertyConfigurator.configure(properties);
        inited = true;
        // 如果最高优先级的文件是在磁盘上,且有写权限,则将merge的结果输出到该目录,方便维护时观察生效的参数
        outputFile(loader.getFoundResList(), properties);
    }
}
Also used : Properties(java.util.Properties) PropertiesLoader(io.servicecomb.foundation.common.config.impl.PropertiesLoader) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

PropertiesLoader (io.servicecomb.foundation.common.config.impl.PropertiesLoader)2 IncConfigs (io.servicecomb.foundation.common.config.impl.IncConfigs)1 IncConfig (io.servicecomb.foundation.common.config.impl.IncConfigs.IncConfig)1 XmlLoader (io.servicecomb.foundation.common.config.impl.XmlLoader)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 Properties (java.util.Properties)1 Resource (org.springframework.core.io.Resource)1