Skip to content

Commit c01e1b8

Browse files
committed
Document purpose of the name attribute in @propertysource
Closes gh-30195
1 parent 2e4e43b commit c01e1b8

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

spring-context/src/main/java/org/springframework/context/annotation/PropertySource.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,28 @@
171171
public @interface PropertySource {
172172

173173
/**
174-
* Indicate the name of this property source. If omitted, the {@link #factory}
175-
* will generate a name based on the underlying resource (in the case of
176-
* {@link org.springframework.core.io.support.DefaultPropertySourceFactory}:
177-
* derived from the resource description through a corresponding name-less
178-
* {@link org.springframework.core.io.support.ResourcePropertySource} constructor).
174+
* Indicate the unique name of this property source.
175+
* <p>If omitted, the {@link #factory} will generate a name based on the
176+
* underlying resource (in the case of
177+
* {@link org.springframework.core.io.support.DefaultPropertySourceFactory
178+
* DefaultPropertySourceFactory}: derived from the resource description through
179+
* a corresponding name-less
180+
* {@link org.springframework.core.io.support.ResourcePropertySource
181+
* ResourcePropertySource} constructor).
182+
* <p>The name of a {@code PropertySource} serves two general purposes.
183+
* <ul>
184+
* <li>Diagnostics: to determine the source of the properties in logging and
185+
* debugging &mdash; for example, in a Spring Boot application via Spring
186+
* Boot's {@code PropertySourceOrigin}.</li>
187+
* <li>Programmatic interaction with
188+
* {@link org.springframework.core.env.MutablePropertySources MutablePropertySources}:
189+
* the name can be used to retrieve properties from a particular property
190+
* source (or to determine if a particular named property source already exists).
191+
* The name can also be used to add a new property source relative to an existing
192+
* property source (see
193+
* {@link org.springframework.core.env.MutablePropertySources#addBefore addBefore()} and
194+
* {@link org.springframework.core.env.MutablePropertySources#addAfter addAfter()}).</li>
195+
* </ul>
179196
* @see org.springframework.core.env.PropertySource#getName()
180197
* @see org.springframework.core.io.Resource#getDescription()
181198
*/

0 commit comments

Comments
 (0)