Merge branch '2.4.x'

Closes gh-24812
This commit is contained in:
Madhura Bhave
2021-01-13 15:18:45 -08:00
4 changed files with 27 additions and 5 deletions

View File

@@ -16,9 +16,11 @@
package org.springframework.boot.context.config;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -171,11 +173,22 @@ public class StandardConfigDataLocationResolver
String directory, String profile) {
Set<StandardConfigDataReference> references = new LinkedHashSet<>();
for (String name : this.configNames) {
for (PropertySourceLoader propertySourceLoader : this.propertySourceLoaders) {
for (String extension : propertySourceLoader.getFileExtensions()) {
StandardConfigDataReference reference = new StandardConfigDataReference(configDataLocation,
directory, directory + name, profile, extension, propertySourceLoader);
references.add(reference);
Deque<StandardConfigDataReference> referencesForName = getReferencesForConfigName(name, configDataLocation,
directory, profile);
references.addAll(referencesForName);
}
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);
}
}
}

View File

@@ -135,6 +135,13 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
assertThat(property).isEqualTo("frompropertiesfile");
}
@Test
void runWhenPropertiesAndYamlShouldPreferProperties() {
ConfigurableApplicationContext context = this.application.run();
String property = context.getEnvironment().getProperty("duplicate");
assertThat(property).isEqualTo("properties");
}
@Test
void runWhenMultipleCustomNamesLoadsEachName() {
ConfigurableApplicationContext context = this.application

View File

@@ -3,3 +3,4 @@ value: 1234
my.property: fromapplicationproperties
sample.app.test.prop: *
my.placeholder: ${my.fallback}
duplicate=properties

View File

@@ -0,0 +1 @@
duplicate: yaml