Top Description Fields Constructors Methods
org.springframework.core.env

public Class CompositePropertySource

extends EnumerablePropertySource<Object>
Class Inheritance
Imports
java.util.ArrayList, .Collection, .Collections, .LinkedHashSet, .List, .Set, org.springframework.lang.Nullable, org.springframework.util.StringUtils

Composite PropertySource implementation that iterates over a set of PropertySource instances. Necessary in cases where multiple property sources share the same name, e.g. when multiple values are supplied to @PropertySource.

As of Spring 4.1.2, this class extends EnumerablePropertySource instead of plain PropertySource, exposing getPropertyNames() based on the accumulated property names from all contained sources (as far as possible).

Authors
Chris Beams, Juergen Hoeller, Phillip Webb
Since
3.1.1

Field Summary

Modifier and TypeField and Description
private final Set<PropertySource<?>>

Constructor Summary

AccessConstructor and Description
public
CompositePropertySource(String
the name of the property source
name
)

Create a new CompositePropertySource.

Method Summary

Modifier and TypeMethod and Description
public void
addFirstPropertySource(PropertySource<?>
the PropertySource to add
propertySource
)

Add the given PropertySource to the start of the chain.

public void
addPropertySource(PropertySource<?>
the PropertySource to add
propertySource
)

Add the given PropertySource to the end of the chain.

public boolean
containsProperty(String
the name of the property to find
name
)

Overrides org.springframework.core.env.EnumerablePropertySource.containsProperty.

Return whether this PropertySource contains a property with the given name.

public Object
getProperty(String
the property to find
name
)

Implements abstract org.springframework.core.env.PropertySource.getProperty.

Return the value associated with the given name, or null if not found.

public String[]
getPropertyNames()

Implements abstract org.springframework.core.env.EnumerablePropertySource.getPropertyNames.

Return the names of all properties contained by the source object (never null).

public Collection<PropertySource<?>>
getPropertySources()

Return all property sources that this composite source holds.

public String
toString()

Overrides org.springframework.core.env.PropertySource.toString.

Produce concise output (type and name) if the current log level does not include debug.

Field Detail

propertySourcesback to summary
private final Set<PropertySource<?>> propertySources

Constructor Detail

CompositePropertySourceback to summary
public CompositePropertySource(String name)

Create a new CompositePropertySource.

Parameters
name:String

the name of the property source

Method Detail

addFirstPropertySourceback to summary
public void addFirstPropertySource(PropertySource<?> propertySource)

Add the given PropertySource to the start of the chain.

Parameters
propertySource:PropertySource<?>

the PropertySource to add

Since
4.1
addPropertySourceback to summary
public void addPropertySource(PropertySource<?> propertySource)

Add the given PropertySource to the end of the chain.

Parameters
propertySource:PropertySource<?>

the PropertySource to add

containsPropertyback to summary
public boolean containsProperty(String name)

Overrides org.springframework.core.env.EnumerablePropertySource.containsProperty.

Doc from org.springframework.core.env.EnumerablePropertySource.containsProperty.

Return whether this PropertySource contains a property with the given name.

This implementation checks for the presence of the given name within the getPropertyNames() array.

Parameters
name:String

the name of the property to find

Annotations
@Override
getPropertyback to summary
public Object getProperty(String name)

Implements abstract org.springframework.core.env.PropertySource.getProperty.

Doc from org.springframework.core.env.PropertySource.getProperty.

Return the value associated with the given name, or null if not found.

Parameters
name:String

the property to find

Annotations
@Override
@Nullable
getPropertyNamesback to summary
public String[] getPropertyNames()

Implements abstract org.springframework.core.env.EnumerablePropertySource.getPropertyNames.

Doc from org.springframework.core.env.EnumerablePropertySource.getPropertyNames.

Return the names of all properties contained by the source object (never null).

Annotations
@Override
getPropertySourcesback to summary
public Collection<PropertySource<?>> getPropertySources()

Return all property sources that this composite source holds.

Since
4.1.1
toStringback to summary
public String toString()

Overrides org.springframework.core.env.PropertySource.toString.

Doc from org.springframework.core.env.PropertySource.toString.

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.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override