Merge branch '6.0.x'

This commit is contained in:
Sam Brannen 2023-08-31 13:40:31 +02:00
commit 093d6a1bec
2 changed files with 34 additions and 14 deletions

View File

@ -169,11 +169,28 @@ import org.springframework.core.io.support.PropertySourceFactory;
public @interface PropertySource {
/**
* Indicate the name of this property source. If omitted, the {@link #factory}
* will generate a name based on the underlying resource (in the case of
* {@link org.springframework.core.io.support.DefaultPropertySourceFactory}:
* derived from the resource description through a corresponding name-less
* {@link org.springframework.core.io.support.ResourcePropertySource} constructor).
* Indicate the unique name of this property source.
* <p>If omitted, the {@link #factory} will generate a name based on the
* underlying resource (in the case of
* {@link org.springframework.core.io.support.DefaultPropertySourceFactory
* DefaultPropertySourceFactory}: derived from the resource description through
* a corresponding name-less
* {@link org.springframework.core.io.support.ResourcePropertySource
* ResourcePropertySource} constructor).
* <p>The name of a {@code PropertySource} serves two general purposes.
* <ul>
* <li>Diagnostics: to determine the source of the properties in logging and
* debugging &mdash; for example, in a Spring Boot application via Spring
* Boot's {@code PropertySourceOrigin}.</li>
* <li>Programmatic interaction with
* {@link org.springframework.core.env.MutablePropertySources MutablePropertySources}:
* the name can be used to retrieve properties from a particular property
* source (or to determine if a particular named property source already exists).
* The name can also be used to add a new property source relative to an existing
* property source (see
* {@link org.springframework.core.env.MutablePropertySources#addBefore addBefore()} and
* {@link org.springframework.core.env.MutablePropertySources#addAfter addAfter()}).</li>
* </ul>
* @see org.springframework.core.env.PropertySource#getName()
* @see org.springframework.core.io.Resource#getDescription()
*/

View File

@ -92,6 +92,8 @@ public abstract class PropertySource<T> {
/**
* Return the name of this {@code PropertySource}.
* <p>See the {@linkplain PropertySource class-level Javadoc} for details
* on property source identity and names.
*/
public String getName() {
return this.name;
@ -170,21 +172,22 @@ public abstract class PropertySource<T> {
/**
* Return a {@code PropertySource} implementation intended for collection comparison purposes only.
* <p>Primarily for internal use, but given a collection of {@code PropertySource} objects, may be
* used as follows:
* Return a {@code PropertySource} implementation intended for collection
* comparison purposes only.
* <p>Primarily for internal use, but given a collection of {@code PropertySource}
* objects, may be used as follows:
* <pre class="code">
* {@code List<PropertySource<?>> sources = new ArrayList<PropertySource<?>>();
* List&lt;PropertySource&lt;?&gt;&gt; sources = new ArrayList&lt;&gt;();
* sources.add(new MapPropertySource("sourceA", mapA));
* sources.add(new MapPropertySource("sourceB", mapB));
* assert sources.contains(PropertySource.named("sourceA"));
* assert sources.contains(PropertySource.named("sourceB"));
* assert !sources.contains(PropertySource.named("sourceC"));
* }</pre>
* The returned {@code PropertySource} will throw {@code UnsupportedOperationException}
* assert !sources.contains(PropertySource.named("sourceC"));</pre>
* <p>The returned {@code PropertySource} will throw {@code UnsupportedOperationException}
* if any methods other than {@code equals(Object)}, {@code hashCode()}, and {@code toString()}
* are called.
* @param name the name of the comparison {@code PropertySource} to be created and returned.
* @param name the name of the comparison {@code PropertySource} to be created
* and returned
*/
public static PropertySource<?> named(String name) {
return new ComparisonPropertySource(name);
@ -206,7 +209,7 @@ public abstract class PropertySource<T> {
public static class StubPropertySource extends PropertySource<Object> {
public StubPropertySource(String name) {
super(name, new Object());
super(name);
}
/**