Class PropertySource<T>
- Type Parameters:
- T- the source type
- Direct Known Subclasses:
- EnumerablePropertySource,- JndiPropertySource,- PropertySource.StubPropertySource
T that encapsulates
 properties. Examples include Properties objects, 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.
- Since:
- 3.1
- Author:
- Chris Beams
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classPropertySourceto be used as a placeholder in cases where an actual property source cannot be eagerly initialized at application context creation time.
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionPropertySource(String name) Create a newPropertySourcewith the given name and with a newObjectinstance as the underlying source.PropertySource(String name, T source) Create a newPropertySourcewith the given name and source object.
- 
Method SummaryModifier and TypeMethodDescriptionbooleancontainsProperty(String name) Return whether thisPropertySourcecontains the given name.booleanThisPropertySourceobject is equal to the given object if: they are the same instance thenameproperties for both objects are equalgetName()Return the name of thisPropertySource.getProperty(String name) Return the value associated with the given name, ornullif not found.Return the underlying source object for thisPropertySource.inthashCode()Return a hash code derived from thenameproperty of thisPropertySourceobject.static PropertySource<?> Return aPropertySourceimplementation intended for collection comparison purposes only.toString()Produce concise output (type and name) if the current log level does not include debug.
- 
Field Details- 
loggerprotected final org.apache.commons.logging.Log logger
- 
name
- 
source
 
- 
- 
Constructor Details- 
PropertySource
- 
PropertySourceCreate a newPropertySourcewith the given name and with a newObjectinstance as the underlying source.Often useful in testing scenarios when creating anonymous implementations that never query an actual source but rather return hard-coded values. 
 
- 
- 
Method Details- 
getNameReturn the name of thisPropertySource.See the class-level Javadoc for details on property source identity and names. 
- 
getSourceReturn the underlying source object for thisPropertySource.
- 
containsPropertyReturn whether thisPropertySourcecontains the given name.This implementation simply checks for a nullreturn value fromgetProperty(String). Subclasses may wish to implement a more efficient algorithm if possible.- Parameters:
- name- the property name to find
 
- 
getProperty
- 
equals
- 
hashCode
- 
toStringProduce 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. 
- 
namedReturn aPropertySourceimplementation intended for collection comparison purposes only.Primarily for internal use, but given a collection of PropertySourceobjects, may be used as follows: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 PropertySourcewill throwUnsupportedOperationExceptionif any methods other thanequals(Object),hashCode(), andtoString()are called.- Parameters:
- name- the name of the comparison- PropertySourceto be created and returned
 
 
-