T that encapsulates
properties. Examples include java.util.Properties objects, java.util.Map
objects, ServletContext and ServletConfig objects (for access to init
parameters). Explore the PropertySource type hierarchy to see provided
implementations.
PropertySource objects are not typically used in isolation, but rather
through a PropertySources object, which aggregates property sources and in
conjunction with a PropertyResolver implementation that can perform
precedence-based searches across the set of PropertySources.
PropertySource identity is determined not based on the content of
encapsulated properties, but rather based on the name of the
PropertySource alone. This is useful for manipulating PropertySource
objects when in collection contexts. See operations in MutablePropertySources
as well as the named(String) and toString() methods for details.
Note that when working with @Configuration classes that
the @PropertySource
annotation provides a convenient and declarative way of adding property sources to the
enclosing Environment.
PropertySources, PropertyResolver, PropertySourcesPropertyResolver, MutablePropertySources, org.springframework.context.annotation.PropertySource
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | PropertySource.
A |
| public static class | PropertySource.
|
| Modifier and Type | Field and Description |
|---|---|
| protected final Log | |
| protected final String | |
| protected final T |
| Access | Constructor and Description |
|---|---|
| public | PropertySource(String
the associated name name, T the source object source)Create a new |
| public | PropertySource(String name)
Create a new |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | containsProperty(String
the property name to find name)Return whether this |
| public boolean | equals(Object
the reference object with which to compare. other)Overrides java. This
|
| public String | |
| public abstract Object | getProperty(String
the property to find name)Return the value associated with the given name,
or |
| public T | |
| public int | hashCode()
Overrides java. Return a hash code derived from the |
| public static PropertySource | |
| public String | toString()
Overrides java. Produce concise output (type and name) if the current log level does not include debug. |
| logger | back to summary |
|---|---|
| protected final Log logger | |
| name | back to summary |
|---|---|
| protected final String name | |
| source | back to summary |
|---|---|
| protected final T source | |
| PropertySource | back to summary |
|---|---|
| public PropertySource(String name, T source) Create a new
| |
| PropertySource | back to summary |
|---|---|
| public PropertySource(String name) Create a new Often useful in testing scenarios when creating anonymous implementations that never query an actual source but rather return hard-coded values.
| |
| containsProperty | back to summary |
|---|---|
| public boolean containsProperty(String name) Return whether this This implementation simply checks for a
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) Overrides java. This
No properties other than
| |
| getName | back to summary |
|---|---|
| public String getName() Return the name of this See the class-level Javadoc for details on property source identity and names. | |
| getProperty | back to summary |
|---|---|
| public abstract Object getProperty(String name) Return the value associated with the given name,
or
| |
| getSource | back to summary |
|---|---|
| public T getSource() Return the underlying source object for this | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Return a hash code derived from the
| |
| named | back to summary |
|---|---|
| public static PropertySource Return a Primarily for internal use, but given a collection of
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
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Produce concise output (type and name) if the current log level does not include debug. If debug is enabled, produce verbose output including the hash code of the PropertySource instance and every name/value property pair. This variable verbosity is useful as a property source such as system properties or environment variables may contain an arbitrary number of property pairs, potentially leading to difficulties to read exception and log messages.
| |
PropertySource implementation intended for collection comparison
purposes.
PropertySource#named(String)
| Modifier and Type | Field and Description |
|---|---|
| private static final String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | containsProperty(String
the property name to find name)Overrides org. Return whether this |
| public String | getProperty(String
the property to find name)Overrides org. Always returns |
| public Object | getSource()
Overrides org. Return the underlying source object for this |
| USAGE_ERROR | back to summary |
|---|---|
| private static final String USAGE_ERROR | |
| ComparisonPropertySource | back to summary |
|---|---|
| public ComparisonPropertySource(String name) | |
| containsProperty | back to summary |
|---|---|
| public boolean containsProperty(String name) Overrides org. Doc from org. Return whether this This implementation simply checks for a | |
| getProperty | back to summary |
|---|---|
| public String getProperty(String name) Overrides org. Doc from org. Always returns
| |
| getSource | back to summary |
|---|---|
| public Object getSource() Overrides org. Doc from org. Return the underlying source object for this
| |
PropertySource to be used as a placeholder in cases where an actual
property source cannot be eagerly initialized at application context
creation time. For example, a ServletContext-based property source
must wait until the ServletContext object is available to its enclosing
ApplicationContext. In such cases, a stub should be used to hold the
intended default position/order of the property source, then be replaced
during context refresh.
org.springframework.context.support.AbstractApplicationContext#initPropertySources() , org.springframework.web.context.support.StandardServletEnvironment , org.springframework.web.context.support.ServletContextPropertySource
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String | getProperty(String
the property to find name)Implements abstract org. Always returns |
| StubPropertySource | back to summary |
|---|---|
| public StubPropertySource(String name) | |
| getProperty | back to summary |
|---|---|
| public String getProperty(String name) Implements abstract org. Always returns
| |