parent
9a48423a1d
commit
ceff47afba
|
|
@ -16,9 +16,11 @@
|
||||||
|
|
||||||
package org.springframework.boot.context.config;
|
package org.springframework.boot.context.config;
|
||||||
|
|
||||||
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Deque;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
@ -171,11 +173,22 @@ public class StandardConfigDataLocationResolver
|
||||||
String directory, String profile) {
|
String directory, String profile) {
|
||||||
Set<StandardConfigDataReference> references = new LinkedHashSet<>();
|
Set<StandardConfigDataReference> references = new LinkedHashSet<>();
|
||||||
for (String name : this.configNames) {
|
for (String name : this.configNames) {
|
||||||
for (PropertySourceLoader propertySourceLoader : this.propertySourceLoaders) {
|
Deque<StandardConfigDataReference> referencesForName = getReferencesForConfigName(name, configDataLocation,
|
||||||
for (String extension : propertySourceLoader.getFileExtensions()) {
|
directory, profile);
|
||||||
StandardConfigDataReference reference = new StandardConfigDataReference(configDataLocation,
|
references.addAll(referencesForName);
|
||||||
directory, directory + name, profile, extension, propertySourceLoader);
|
}
|
||||||
references.add(reference);
|
return references;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Deque<StandardConfigDataReference> getReferencesForConfigName(String name,
|
||||||
|
ConfigDataLocation configDataLocation, String directory, String profile) {
|
||||||
|
Deque<StandardConfigDataReference> references = new ArrayDeque<>();
|
||||||
|
for (PropertySourceLoader propertySourceLoader : this.propertySourceLoaders) {
|
||||||
|
for (String extension : propertySourceLoader.getFileExtensions()) {
|
||||||
|
StandardConfigDataReference reference = new StandardConfigDataReference(configDataLocation, directory,
|
||||||
|
directory + name, profile, extension, propertySourceLoader);
|
||||||
|
if (!references.contains(reference)) {
|
||||||
|
references.addFirst(reference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,13 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
|
||||||
assertThat(property).isEqualTo("frompropertiesfile");
|
assertThat(property).isEqualTo("frompropertiesfile");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void runWhenPropertiesAndYamlShouldPreferProperties() {
|
||||||
|
ConfigurableApplicationContext context = this.application.run();
|
||||||
|
String property = context.getEnvironment().getProperty("duplicate");
|
||||||
|
assertThat(property).isEqualTo("properties");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void runWhenMultipleCustomNamesLoadsEachName() {
|
void runWhenMultipleCustomNamesLoadsEachName() {
|
||||||
ConfigurableApplicationContext context = this.application
|
ConfigurableApplicationContext context = this.application
|
||||||
|
|
|
||||||
|
|
@ -3,3 +3,4 @@ value: 1234
|
||||||
my.property: fromapplicationproperties
|
my.property: fromapplicationproperties
|
||||||
sample.app.test.prop: *
|
sample.app.test.prop: *
|
||||||
my.placeholder: ${my.fallback}
|
my.placeholder: ${my.fallback}
|
||||||
|
duplicate=properties
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
duplicate: yaml
|
||||||
Loading…
Reference in New Issue