Package org.springframework.core.env
Class SystemEnvironmentPropertySource
java.lang.Object
org.springframework.core.env.PropertySource<T>
org.springframework.core.env.EnumerablePropertySource<Map<String,Object>>
org.springframework.core.env.MapPropertySource
org.springframework.core.env.SystemEnvironmentPropertySource
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:
foo.bar
- the original namefoo_bar
- with underscores for periods (if any)FOO.BAR
- original, with upper caseFOO_BAR
- with underscores and upper case
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 ... 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 StandardEnvironment
and all its subclasses.
- Since:
- 3.1
- Author:
- Chris Beams, Juergen Hoeller
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.core.env.PropertySource
PropertySource.StubPropertySource
-
Field Summary
Fields inherited from class org.springframework.core.env.PropertySource
logger, name, source
-
Constructor Summary
ConstructorDescriptionSystemEnvironmentPropertySource
(String name, Map<String, Object> source) Create a newSystemEnvironmentPropertySource
with the given name and delegating to the givenMapPropertySource
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsProperty
(String name) Returntrue
if a property with the given name or any underscore/uppercase variant thereof exists in this property source.getProperty
(String name) This implementation returnstrue
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.Methods inherited from class org.springframework.core.env.MapPropertySource
getPropertyNames
-
Constructor Details
-
SystemEnvironmentPropertySource
Create a newSystemEnvironmentPropertySource
with the given name and delegating to the givenMapPropertySource
.
-
-
Method Details
-
containsProperty
Returntrue
if a property with the given name or any underscore/uppercase variant thereof exists in this property source.- Overrides:
containsProperty
in classMapPropertySource
- Parameters:
name
- the name of the property to find
-
getProperty
This implementation returnstrue
if a property with the given name or any underscore/uppercase variant thereof exists in this property source.- Overrides:
getProperty
in classMapPropertySource
- Parameters:
name
- the property to find- See Also:
-
resolvePropertyName
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 returnsnull
.
-