MapPropertySource class
A property source over a map of keys to values.
It is the simplest way to put values into the environment from code:
defaults computed at startup, values for a test, a parsed file. Many
framework sources build on it (environment variables, .properties
files, YAML documents). Keys are written in full (server.port), not
nested; values may be strings, numbers, booleans or lists and are
converted on read.
The map is used as is, not copied, so later changes to it are seen.
// Values computed at startup, below every other source.
final defaults = MapPropertySource('defaults', {
'server.port': 8080,
'app.name': 'demo',
});
environment.propertySources.addLast(defaults);
Spring (Java):
var defaults = new MapPropertySource("defaults",
Map.of("server.port", 8080, "app.name", "demo"));
environment.getPropertySources().addLast(defaults);
- Inheritance
-
- Object
- AbstractPropertySource<
Map< String, Object?> > - EnumerablePropertySource<
Map< String, Object?> > - MapPropertySource
Constructors
-
MapPropertySource(String name, Map<
String, Object?> source) -
Creates a source called
nameover the mapsource, without copying it.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 setteroverride
- 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 anullvalue.override -
getProperty(
String name) → Object? -
The value of the property
name, ornullwhen this source does not have it (the environment then asks the next source).override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
Whether
otheris a source with the same name, whatever its values, as in Spring.inherited