Top Description Constructors Methods
org.springframework.core.env

public Class SystemEnvironmentPropertySource

extends MapPropertySource
Class Inheritance
Imports
java.util.Map, org.springframework.lang.Nullable, org.springframework.util.Assert

Specialization of MapPropertySource designed for use with system environment variables. Compensates for constraints in Bash and other shells that do not allow for variables containing the period character and/or hyphen character; also allows for uppercase variations on property names for more idiomatic shell use.

For example, a call to getProperty("foo.bar") will attempt to find a value for the original property or any 'equivalent' property, returning the first found:

Any hyphen variant of the above would work as well, or even mix dot/hyphen variants.

The same applies for calls to containsProperty(String), which returns true if any of the above properties are present, otherwise false.

This feature is particularly useful when specifying active or default profiles as environment variables. The following is not allowable under Bash:

spring.profiles.active=p1 java -classpath ... MyApp
However, the following syntax is permitted and is also more conventional:
SPRING_PROFILES_ACTIVE=p1 java -classpath ... MyApp

Enable debug- or trace-level logging for this class (or package) for messages explaining when these 'property name resolutions' occur.

This property source is included by default in StandardEnvironment and all its subclasses.

Authors
Chris Beams, Juergen Hoeller
Since
3.1
See Also
StandardEnvironment, AbstractEnvironment#getSystemEnvironment(), AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME

Constructor Summary

AccessConstructor and Description
public
SystemEnvironmentPropertySource(String name, Map<String, Object> source)

Create a new SystemEnvironmentPropertySource with the given name and delegating to the given MapPropertySource.

Method Summary

Modifier and TypeMethod and Description
private String
public boolean
containsProperty(String
the name of the property to find
name
)

Overrides org.springframework.core.env.MapPropertySource.containsProperty.

Return true if a property with the given name or any underscore/uppercase variant thereof exists in this property source.

public Object
getProperty(String
the property to find
name
)

Overrides org.springframework.core.env.MapPropertySource.getProperty.

This implementation returns true if a property with the given name or any underscore/uppercase variant thereof exists in this property source.

protected final String
resolvePropertyName(String name)

Check to see if this property source contains a property with the given name, or any underscore / uppercase variation thereof.

Inherited from org.springframework.core.env.MapPropertySource:
getPropertyNames

Constructor Detail

SystemEnvironmentPropertySourceback to summary
public SystemEnvironmentPropertySource(String name, Map<String, Object> source)

Create a new SystemEnvironmentPropertySource with the given name and delegating to the given MapPropertySource.

Method Detail

checkPropertyNameback to summary
private String checkPropertyName(String name)
Annotations
@Nullable
containsPropertyback to summary
public boolean containsProperty(String name)

Overrides org.springframework.core.env.MapPropertySource.containsProperty.

Return true if a property with the given name or any underscore/uppercase variant thereof exists in this property source.

Parameters
name:String

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

the name of the property to find

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

Overrides org.springframework.core.env.MapPropertySource.getProperty.

This implementation returns true if a property with the given name or any underscore/uppercase variant thereof exists in this property source.

Parameters
name:String

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

the property to find

Annotations
@Override
@Nullable
resolvePropertyNameback to summary
protected final String resolvePropertyName(String name)

Check to see if this property source contains a property with the given name, or any underscore / uppercase variation thereof. Return the resolved name if one is found or otherwise the original name. Never returns null.