Skip to content

Commit 0867dfc

Browse files
committed
Introduce CompositePropertySource constructor that accepts Iterable<PropertySource>
This commit introduces a new constructor for CompositePropertySource that accepts a `String name` and an Iterable<PropertySource<?>>, which allows a CompositePropertySource to be constructed from existing property sources, such as an instance of MutablePropertySources. Closes gh-34862
1 parent b4355dc commit 0867dfc

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

spring-core/src/main/java/org/springframework/core/env/CompositePropertySource.java

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@
3939
* @author Chris Beams
4040
* @author Juergen Hoeller
4141
* @author Phillip Webb
42+
* @author Sam Brannen
4243
* @since 3.1.1
4344
*/
4445
public class CompositePropertySource extends EnumerablePropertySource<Object> {
@@ -47,13 +48,35 @@ public class CompositePropertySource extends EnumerablePropertySource<Object> {
4748

4849

4950
/**
50-
* Create a new {@code CompositePropertySource}.
51-
* @param name the name of the property source
51+
* Create a new empty {@code CompositePropertySource} with the given name.
52+
* @param name the name of the composite property source
53+
* @see #CompositePropertySource(String, Iterable)
54+
* @see #addPropertySource(PropertySource)
55+
* @see #addFirstPropertySource(PropertySource)
5256
*/
5357
public CompositePropertySource(String name) {
5458
super(name);
5559
}
5660

61+
/**
62+
* Create a new {@code CompositePropertySource} with the given name and
63+
* property sources supplied as an {@link Iterable} or {@link PropertySources}
64+
* implementation, preserving the original order of the property sources.
65+
* @param name the name of the composite property source
66+
* @param propertySources the initial set of {@link PropertySource} instances
67+
* @since 6.2.7
68+
* @see PropertySources
69+
* @see MutablePropertySources
70+
* @see #addPropertySource(PropertySource)
71+
* @see #addFirstPropertySource(PropertySource)
72+
*/
73+
public CompositePropertySource(String name, Iterable<PropertySource<?>> propertySources) {
74+
this(name);
75+
for (PropertySource<?> propertySource : propertySources) {
76+
this.propertySources.add(propertySource);
77+
}
78+
}
79+
5780

5881
@Override
5982
@Nullable

0 commit comments

Comments
 (0)