org.springframework.boot.env.OriginTrackedMapPropertySource Java Examples
The following examples show how to use
org.springframework.boot.env.OriginTrackedMapPropertySource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: YamlPropertyLoaderFactory.java From magic-starter with GNU Lesser General Public License v3.0 | 8 votes |
@Override public PropertySource<?> createPropertySource(@Nullable String name, EncodedResource encodedResource) throws IOException { if (encodedResource == null) { return emptyPropertySource(name); } Resource resource = encodedResource.getResource(); String fileName = resource.getFilename(); List<PropertySource<?>> sources = new YamlPropertySourceLoader().load(fileName, resource); if (sources.isEmpty()) { return emptyPropertySource(fileName); } // yaml 数据存储,合成一个 PropertySource Map<String, Object> ymlDataMap = new HashMap<>(32); for (PropertySource<?> source : sources) { ymlDataMap.putAll(((MapPropertySource) source).getSource()); } return new OriginTrackedMapPropertySource(getSourceName(fileName, name), ymlDataMap); }
Example #2
Source File: PassthruEnvironmentRepositoryTests.java From spring-cloud-config with Apache License 2.0 | 6 votes |
@Test public void originTrackedPropertySourceWithoutOriginWorks() { MockEnvironment mockEnvironment = new MockEnvironment(); mockEnvironment.setProperty("normalKey", "normalValue"); mockEnvironment.getPropertySources() .addFirst(new OriginTrackedMapPropertySource("myorigintrackedsource", Collections.singletonMap("keyNoOrigin", "valueNoOrigin"))); PassthruEnvironmentRepository repository = new PassthruEnvironmentRepository( mockEnvironment); Environment environment = repository.findOne("testapp", "default", "master", true); assertThat(environment).isNotNull(); List<PropertySource> propertySources = environment.getPropertySources(); assertThat(propertySources).hasSize(2); for (PropertySource propertySource : propertySources) { Map source = propertySource.getSource(); if (propertySource.getName().equals("myorigintrackedsource")) { assertThat(source).containsEntry("keyNoOrigin", "valueNoOrigin"); } else if (propertySource.getName().equals("mockProperties")) { assertThat(source).containsEntry("normalKey", "normalValue"); } } }
Example #3
Source File: BootstrapApplicationListener.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
public void add(PropertySource<?> source) { // Only add map property sources added by boot, see gh-476 if (source instanceof OriginTrackedMapPropertySource && !this.names.contains(source.getName())) { this.sources.addPropertySource(source); this.names.add(source.getName()); } }