use of org.springframework.boot.env.OriginTrackedMapPropertySource in project spring-cloud-alibaba by alibaba.
the class NacosJsonPropertySourceLoader method doLoad.
/**
* Load the resource into one or more property sources. Implementations may either
* return a list containing a single source, or in the case of a multi-document format
* such as yaml a source for each document in the resource.
* @param name the root name of the property source. If multiple documents are loaded
* an additional suffix should be added to the name for each source loaded.
* @param resource the resource to load
* @return a list property sources
* @throws IOException if the source cannot be loaded
*/
@Override
protected List<PropertySource<?>> doLoad(String name, Resource resource) throws IOException {
Map<String, Object> result = new LinkedHashMap<>(32);
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> nacosDataMap = mapper.readValue(resource.getInputStream(), LinkedHashMap.class);
flattenedMap(result, nacosDataMap, null);
return Collections.singletonList(new OriginTrackedMapPropertySource(name, this.reloadMap(result), true));
}
use of org.springframework.boot.env.OriginTrackedMapPropertySource in project spring-boot-web by wangchengming666.
the class ApplicationEnvironmentPreparedListener method handleEnvironment.
public void handleEnvironment() {
Objects.requireNonNull(env);
initFrameworkConstants();
initKeysConstants();
initActiveProfilesConstants();
MutablePropertySources propSources = env.getPropertySources();
StreamSupport.stream(propSources.spliterator(), false).forEach(p -> {
if (p instanceof OriginTrackedMapPropertySource) {
OriginTrackedMapPropertySource o = (OriginTrackedMapPropertySource) p;
initEncryptorConstants(p.getName(), o);
}
});
}
use of org.springframework.boot.env.OriginTrackedMapPropertySource in project mmqtt by MrHKing.
the class StartingApplicationListener method loadPreProperties.
private void loadPreProperties(ConfigurableEnvironment environment) {
try {
SOURCES.putAll(EnvUtil.loadProperties(EnvUtil.getApplicationConfFileResource()));
environment.getPropertySources().addLast(new OriginTrackedMapPropertySource(MMQ_APPLICATION_CONF, SOURCES));
registerWatcher();
} catch (Exception e) {
throw new MmqRuntimeException(MmqException.SERVER_ERROR, e);
}
}
use of org.springframework.boot.env.OriginTrackedMapPropertySource in project mdx-kylin by Kyligence.
the class MdxPropertySourceLoader method load.
@SuppressWarnings("unchecked")
@Override
public List<PropertySource<?>> load(String name, Resource resource) throws IOException {
String filename = resource.getFilename();
List<PropertySource<?>> propertySources;
if (filename == null || filename.endsWith(".properties") || filename.endsWith(".xml")) {
propertySources = propLoader.load(name, resource);
} else {
propertySources = yamlLoader.load(name, resource);
}
List<PropertySource<?>> newSources = new ArrayList<>();
for (PropertySource propertySource : propertySources) {
Map<String, ?> properties = (Map<String, ?>) propertySource.getSource();
Map<String, Object> newProperties = new LinkedHashMap<>();
for (String propertyKey : properties.keySet()) {
Object propertyValue = properties.get(propertyKey);
newProperties.put(propertyKey, handle(propertyKey, propertyValue));
}
newSources.add(new OriginTrackedMapPropertySource(name, Collections.unmodifiableMap(newProperties), true));
}
try {
handleAad();
} catch (Exception e) {
// Nothing to do
log.warn("Failed to handle aad", e);
}
return newSources;
}
use of org.springframework.boot.env.OriginTrackedMapPropertySource in project xuxiaowei-cloud by xuxiaowei-cloud.
the class EnvironmentTests method getEnvironment.
/**
* 获取环境变量
*/
@Test
void getEnvironment() {
Environment environment = nacosConfigProperties.getEnvironment();
MutablePropertySources mutablePropertySources = configurableEnvironment.getPropertySources();
mutablePropertySources.forEach(propertySource -> {
if (propertySource instanceof OriginTrackedMapPropertySource) {
OriginTrackedMapPropertySource originTrackedMapPropertySource = (OriginTrackedMapPropertySource) propertySource;
String name = originTrackedMapPropertySource.getName();
Map<String, Object> source = originTrackedMapPropertySource.getSource();
System.out.println("# 配置文件:" + name);
for (String key : source.keySet()) {
System.out.println(key + "= " + source.get(key));
}
System.out.println();
} else if (propertySource instanceof MapPropertySource) {
MapPropertySource mapPropertySource = (MapPropertySource) propertySource;
String name = mapPropertySource.getName();
Object property = mapPropertySource.getProperty(name);
} else if (propertySource instanceof BootstrapPropertySource) {
PropertySource<?> delegate = ((BootstrapPropertySource<?>) propertySource).getDelegate();
if (delegate instanceof NacosPropertySource) {
String name = delegate.getName();
if (environment instanceof StandardServletEnvironment) {
StandardServletEnvironment standardServletEnvironment = (StandardServletEnvironment) environment;
MutablePropertySources propertySources = standardServletEnvironment.getPropertySources();
PropertySource<?> bootstrapProperties = propertySources.get("bootstrapProperties-" + name);
assert bootstrapProperties != null;
Object source = bootstrapProperties.getSource();
if (source instanceof LinkedHashMap) {
LinkedHashMap<?, ?> linkedHashMap = (LinkedHashMap<?, ?>) source;
System.out.println("# 配置文件:" + name);
for (Object key : linkedHashMap.keySet()) {
System.out.println(key + "= " + linkedHashMap.get(key));
}
System.out.println();
}
}
}
}
});
}
Aggregations