private void loadDiamondDataIfPresent(final CompositePropertySource composite, final String dataId, final String diamondGroup, final boolean groupLevel) { AcmPropertySource ps = acmPropertySourceBuilder.build(dataId, diamondGroup, groupLevel); if (ps != null) { composite.addFirstPropertySource(ps); } } }
private void addPropertySourceIfNeeded(Function<String, Map<String, String>> contentToMapFunction, String content, String name, CompositePropertySource composite) { Map<String, Object> map = new HashMap<>(); map.putAll(contentToMapFunction.apply(content)); if(map.isEmpty()) { LOG.warn("Property source: " + name + "will be ignored because no properties could be found"); } else { composite.addFirstPropertySource(new MapPropertySource(name, map)); } } }
private void loadNacosDataIfPresent(final CompositePropertySource composite, final String dataId, final String group, String fileExtension, boolean isRefreshable) { if (NacosContextRefresher.getRefreshCount() != 0) { NacosPropertySource ps; if (!isRefreshable) { ps = NacosPropertySourceRepository.getNacosPropertySource(dataId); } else { ps = nacosPropertySourceBuilder.build(dataId, group, fileExtension, true); } composite.addFirstPropertySource(ps); } else { NacosPropertySource ps = nacosPropertySourceBuilder.build(dataId, group, fileExtension, isRefreshable); composite.addFirstPropertySource(ps); } }
((ResourcePropertySource) propertySource).withResourceName() : propertySource); if (existing instanceof CompositePropertySource) { ((CompositePropertySource) existing).addFirstPropertySource(newSource);
((ResourcePropertySource) propertySource).withResourceName() : propertySource); if (existing instanceof CompositePropertySource) { ((CompositePropertySource) existing).addFirstPropertySource(newSource);
compositeSource.addFirstPropertySource(props); LOG.debug(String.format("Added property source %s at the beginning of the composite source ", props.getName(), compositeSource.getName()));
@Test public void addFirst() { PropertySource<?> p1 = new MapPropertySource("p1", Collections.emptyMap()); PropertySource<?> p2 = new MapPropertySource("p2", Collections.emptyMap()); PropertySource<?> p3 = new MapPropertySource("p3", Collections.emptyMap()); CompositePropertySource composite = new CompositePropertySource("c"); composite.addPropertySource(p2); composite.addPropertySource(p3); composite.addPropertySource(p1); composite.addFirstPropertySource(p1); String s = composite.toString(); int i1 = s.indexOf("name='p1'"); int i2 = s.indexOf("name='p2'"); int i3 = s.indexOf("name='p3'"); assertTrue("Bad order: " + s, ((i1 < i2) && (i2 < i3))); }
@Override public PropertySource locate(Environment environment) { if (environment instanceof ConfigurableEnvironment) { ConfigurableEnvironment env = (ConfigurableEnvironment) environment; List<ConfigMapConfigProperties.NormalizedSource> sources = properties .determineSources(); CompositePropertySource composite = new CompositePropertySource( "composite-configmap"); if (properties.isEnableApi()) { sources.forEach(s -> composite.addFirstPropertySource( getMapPropertySourceForSingleConfigMap(env, s))); } addPropertySourcesFromPaths(environment, composite); return composite; } return null; }
putValue(map, "config.client.state", result.getState()); putValue(map, "config.client.version", result.getVersion()); composite.addFirstPropertySource( new MapPropertySource("configClient", map));
private void addPropertySourceIfNeeded(Function<String, Map<String, String>> contentToMapFunction, String content, String name, CompositePropertySource composite) { Map<String, Object> map = new HashMap<>(); map.putAll(contentToMapFunction.apply(content)); if(map.isEmpty()) { LOG.warn("Property source: " + name + "will be ignored because no properties could be found"); } else { composite.addFirstPropertySource(new MapPropertySource(name, map)); } } }
/** * Property files processed in order of non-profiles first and then profiles, and profiles are first to last * with properties in the last profile overriding properties in previous profiles or non-profiles. * * @param environment Spring environment * @param config Location of config files * @return Merged properties */ private PropertySource<?> loadSettingsByApplicationProfiles(final Environment environment, final File config) { val profiles = ConfigurationPropertiesLoaderFactory.getApplicationProfiles(environment); val resources = scanForConfigurationResources(config, profiles); val composite = new CompositePropertySource("applicationProfilesCompositeProperties"); LOGGER.info("Configuration files found at [{}] are [{}] under profile(s) [{}]", config, resources, profiles); resources.forEach(Unchecked.consumer(f -> { LOGGER.debug("Loading configuration file [{}]", f); val loader = configurationPropertiesLoaderFactory.getLoader(f, "applicationProfilesProperties-" + f.getFilename()); composite.addFirstPropertySource(loader.load()); })); return composite; }
@Override public PropertySource locate(Environment environment) { if (environment instanceof ConfigurableEnvironment) { ConfigurableEnvironment env = (ConfigurableEnvironment) environment; List<ConfigMapConfigProperties.NormalizedSource> sources = properties .determineSources(); CompositePropertySource composite = new CompositePropertySource( "composite-configmap"); if (properties.isEnableApi()) { sources.forEach(s -> composite.addFirstPropertySource( getMapPropertySourceForSingleConfigMap(env, s))); } addPropertySourcesFromPaths(environment, composite); return composite; } return null; }
((ResourcePropertySource) propertySource).withResourceName() : propertySource); if (existing instanceof CompositePropertySource) { ((CompositePropertySource) existing).addFirstPropertySource(newSource);
putValue(map, "config.client.state", result.getState()); putValue(map, "config.client.version", result.getVersion()); composite.addFirstPropertySource( new MapPropertySource("configClient", map));