com.jeesuite.confcenter.springboot.CCPropertySourceLoader Maven / Gradle / Ivy
package com.jeesuite.confcenter.springboot;
import java.io.IOException;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.env.PropertySourceLoader;
import org.springframework.core.PriorityOrdered;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import com.jeesuite.common.util.ResourceUtils;
import com.jeesuite.confcenter.ConfigcenterContext;
public class CCPropertySourceLoader implements PropertySourceLoader,PriorityOrdered,DisposableBean {
private ConfigcenterContext ccContext = ConfigcenterContext.getInstance();
@Override
public String[] getFileExtensions() {
return new String[] { "properties"};
}
@Override
public PropertySource> load(String name, Resource resource, String profile)
throws IOException {
if (profile == null) {
Properties properties = PropertiesLoaderUtils.loadProperties(resource);
ResourceUtils.merge(properties);
ccContext.init(true);
Properties remoteProperties = ccContext.getAllRemoteProperties();
if(remoteProperties != null){
Set> entrySet = remoteProperties.entrySet();
for (Entry