public class SystemEnvironmentPropertySource extends MapPropertySourceSpecialization of
MapPropertySourcedesigned for use with system environment variables. Compensates for constraints in Bash and other shells that do not allow for variables containing the period 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:
foo.bar- the original name
foo_bar- with underscores for periods (if any)
FOO.BAR- original, with upper case
FOO_BAR- with underscores and upper case
containsProperty(String), which returns
trueif any of the above properties are present, otherwise
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 ... MyAppHowever, 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
StandardEnvironmentand all its subclasses.
Nested Class Summary
Fields inherited from class org.springframework.core.env.EnumerablePropertySource
Methods Modifier and Type Method and Description
containsProperty(String name)Return true if a property with the given name or any underscore/uppercase variant thereof exists in this property source.
getProperty(String name)Return the value associated with the given name, or
nullif not found.
Methods inherited from class org.springframework.core.env.PropertySource
equals, getName, getSource, hashCode, named, toString
public boolean containsProperty(String name)Return true if a property with the given name or any underscore/uppercase variant thereof exists in this property source.
getPropertyReturn the value associated with the given name, or
nullif not found.
This implementation returns
trueif a property with the given name or any underscore/uppercase variant thereof exists in this property source.