diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java b/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java index b226fdf42e..7559ce8864 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java @@ -137,8 +137,8 @@ public class PropertySourceProcessor { propertySources.addLast(propertySource); } else { - String firstProcessed = this.propertySourceNames.get(this.propertySourceNames.size() - 1); - propertySources.addBefore(firstProcessed, propertySource); + String lastAdded = this.propertySourceNames.get(this.propertySourceNames.size() - 1); + propertySources.addBefore(lastAdded, propertySource); } this.propertySourceNames.add(name); } diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceAttributes.java b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceAttributes.java index 388784fa39..22efe9dd80 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceAttributes.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceAttributes.java @@ -126,6 +126,9 @@ class TestPropertySourceAttributes { TestContextResourceUtils.convertToClasspathResourcePaths(declaringClass, true, locations); Class factoryClass = (Class) mergedAnnotation.getClass("factory"); + if (factoryClass == PropertySourceFactory.class) { + factoryClass = null; // default factory type will be inferred + } String encoding = mergedAnnotation.getString("encoding"); if (encoding.isBlank()) { encoding = null; // default encoding will be inferred diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java index 5a2514f609..20f8b68165 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java @@ -293,8 +293,7 @@ public abstract class TestPropertySourceUtils { for (PropertySourceDescriptor descriptor : descriptors) { if (!descriptor.locations().isEmpty()) { Class factoryClass = descriptor.propertySourceFactory(); - PropertySourceFactory factory = - (factoryClass != null && factoryClass != PropertySourceFactory.class ? + PropertySourceFactory factory = (factoryClass != null ? BeanUtils.instantiateClass(factoryClass) : defaultPropertySourceFactory); for (String location : descriptor.locations()) {