All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.iohao.profile.ProfileLoadKit Maven / Gradle / Ivy

There is a newer version: 0.5.5
Show newest version
package com.iohao.profile;


import com.iohao.profile.io.support.ResourcePatternResolverConfig;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 配置加载工具
 * 
* create time : 2019-01-11 20:16 * * @author [email protected] */ @Slf4j @UtilityClass public class ProfileLoadKit { /** 加载目录分割符号 */ @Setter @Getter private String separator = ","; /** * 加载配置文件, /resources/conf下面的目录 *
     * 数据格式以,分割.  例如: blocks,local (假设参数传入是这个字符串)
     * 优先加载 blocks 目录下的配置文件.
     * 然后加载 local 目录下的配置文件.
     * 如果两个目录中有相同的配置项, 那么后面的会覆盖前面的配置项
     *
     * 
* * @param profileConfigName 数据格式以,分割. 例如: blocks,local */ public void loadProfile(String profileConfigName) { Optional name = Optional.ofNullable(profileConfigName); List configNameList = Arrays.stream(name.orElse("") .split(separator)) .filter(Objects::nonNull) .map(String::trim) .filter(s -> s.length() > 0) .collect(Collectors.toList()); log.debug("加载的目录列表 - size {} - {}", configNameList.size(), configNameList); // 加载配置 ResourcePatternResolverConfig resolverConfig = new ResourcePatternResolverConfig(); configNameList.forEach(resolverConfig::addDir); ProfileManager.Builder builder = ProfileManager.newBuilder(); builder.addPropFile(resolverConfig.toUrls()); log.debug("配置内容 - size:{} - !{}", ProfileManager.profile().map.size(), ProfileManager.profile()); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy