SystemEnvironmentPropertySource class

The property source over the operating system's environment variables, which finds server.port in the variable SERVER_PORT.

Environment variable names cannot contain dots and are written in upper case by convention, so a direct lookup would never find a property. This source tries the usual spellings: my.prop-name also matches my_prop-name, my.prop_name, my_prop_name, their upper-case forms (MY_PROP_NAME) and the upper-case form without dashes that Spring Boot uses (MY_PROPNAME).

An application does not create it: StandardEnvironment adds one under defaultName, which is why SERVER_PORT=9090 works. On the web the map is empty. Create one yourself only to fake variables, though passing systemEnvironment: to StandardEnvironment is simpler.

// In a test: a variable set as a container would set it.
final source = SystemEnvironmentPropertySource(
  SystemEnvironmentPropertySource.defaultName,
  {'SERVER_PORT': '9090'},
);
source.getProperty('server.port'); // '9090'

Spring (Java):

var source = new SystemEnvironmentPropertySource(
    StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
    Map.of("SERVER_PORT", "9090"));
source.getProperty("server.port"); // "9090"
Inheritance

Constructors

SystemEnvironmentPropertySource(String name, Map<String, Object?> source)
Creates a source called name over the variables in source (variable name to value).
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
name → String
The name of this source, unique within the environment's list. It is how other code finds, replaces or orders the source, and it appears in error messages (Config resource 'resources:/application.yml').
finalinherited
propertyNames → List<String>
The keys of all properties this source has, as they are written in it.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
source → Map<String, Object?>
The object the values are read from: a map, the command-line arguments, a client.
finalinherited

Methods

containsProperty(String name) → bool
Whether the map has the key name, even with a null value.
override
getProperty(String name) → Object?
The value of the first variable whose name is one of the spellings of name, tried in the order of resolvePropertyName.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolvePropertyName(String name) → String?
The name of the variable that holds the property name, or null.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
Whether other is a source with the same name, whatever its values, as in Spring.
inherited

Constants

defaultName → const String
The name StandardEnvironment gives its environment variable source: systemEnvironment.