use of com.alibaba.cloud.nacos.client.NacosPropertySource in project spring-cloud-alibaba by alibaba.
the class NacosContextRefresher method registerNacosListenersForApplications.
/**
* register Nacos Listeners.
*/
private void registerNacosListenersForApplications() {
if (isRefreshEnabled()) {
for (NacosPropertySource propertySource : NacosPropertySourceRepository.getAll()) {
if (!propertySource.isRefreshable()) {
continue;
}
String dataId = propertySource.getDataId();
registerNacosListener(propertySource.getGroup(), dataId);
}
}
}
use of com.alibaba.cloud.nacos.client.NacosPropertySource in project spring-cloud-alibaba by alibaba.
the class NacosConfigEndpoint method invoke.
@ReadOperation
public Map<String, Object> invoke() {
Map<String, Object> result = new HashMap<>(16);
result.put("NacosConfigProperties", properties);
List<NacosPropertySource> all = NacosPropertySourceRepository.getAll();
List<Map<String, Object>> sources = new ArrayList<>();
for (NacosPropertySource ps : all) {
Map<String, Object> source = new HashMap<>(16);
source.put("dataId", ps.getDataId());
source.put("lastSynced", dateFormat.get().format(ps.getTimestamp()));
sources.add(source);
}
result.put("Sources", sources);
result.put("RefreshHistory", refreshHistory.getRecords());
return result;
}
use of com.alibaba.cloud.nacos.client.NacosPropertySource 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