diff --git a/spring-context/src/main/java/org/springframework/context/annotation/PropertySource.java b/spring-context/src/main/java/org/springframework/context/annotation/PropertySource.java index 75d9fc6b8f6..d6e5dc4339a 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/PropertySource.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/PropertySource.java @@ -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. + *

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). + *

The name of a {@code PropertySource} serves two general purposes. + *

* @see org.springframework.core.env.PropertySource#getName() * @see org.springframework.core.io.Resource#getDescription() */ diff --git a/spring-core/src/main/java/org/springframework/core/env/PropertySource.java b/spring-core/src/main/java/org/springframework/core/env/PropertySource.java index f50968d2bba..64ad2c0d928 100644 --- a/spring-core/src/main/java/org/springframework/core/env/PropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/PropertySource.java @@ -92,6 +92,8 @@ public abstract class PropertySource { /** * Return the name of this {@code PropertySource}. + *

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 { /** - * Return a {@code PropertySource} implementation intended for collection comparison purposes only. - *

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. + *

Primarily for internal use, but given a collection of {@code PropertySource} + * objects, may be used as follows: *

-	 * {@code List> sources = new ArrayList>();
+	 * List<PropertySource<?>> sources = new ArrayList<>();
 	 * 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"));
-	 * }
- * The returned {@code PropertySource} will throw {@code UnsupportedOperationException} + * assert !sources.contains(PropertySource.named("sourceC")); + *

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 { public static class StubPropertySource extends PropertySource { public StubPropertySource(String name) { - super(name, new Object()); + super(name); } /**