core library

The foundations under the container: the environment (properties, profiles, config files, placeholders), type conversion, resources, ordering and logging.

Import it for code that reads configuration or files without needing the container, such as a command-line tool, a test or a library; most applications import spring_core_dart.dart (or a starter), which includes it. What it holds:

  • Environment, StandardEnvironment and the property sources: where properties come from and which one wins; Profiles for profile conditions.
  • ConfigDataEnvironment: reads application.properties and application.yml (with profiles, imports and config trees) into an environment, as Spring Boot does.
  • ConversionService and DefaultConversionService: turn text into int, Duration, DataSize, lists, enums and your own types.
  • Resource, ResourceLoader and ResourcePatternResolver: read classpath: (lib/resources/), file:, http: and custom locations; AntPathMatcher for wildcards.
  • Ordered, Order and OrderComparator: the order of beans run or injected in turn.
  • SpringLog and @Log(): logging for the framework and applications.
// A tool that reads the application's configuration without a
// container.
Future<void> main(List<String> args) async {
  final environment = StandardEnvironment()
    ..propertySources.addFirst(SimpleCommandLinePropertySource(args));
  await ConfigDataEnvironment(environment).processAndApply();
  final port = environment.getPropertyAs<int>('server.port') ?? 8080;
  final dev = environment.matchesProfiles(['dev']);
}

Spring (Java):

ConfigurableEnvironment environment = new StandardEnvironment();
// Spring Boot loads application.properties into it on startup.
int port = environment.getProperty("server.port", Integer.class, 8080);
boolean dev = environment.matchesProfiles("dev");

This is Spring's spring-core plus Spring Boot's config data.

Classes

AbstractPropertyResolver
The common part of property resolvers: placeholder resolution, conversion, defaults and required keys. A subclass only says where raw values come from, in getRawProperty.
AbstractPropertySource<T extends Object>
One place property values come from, under a name: a config file, the command line, the environment variables, a map of defaults.
AbstractResource
A base class for new kinds of Resource: it fills in everything that can be derived from a few members.
AntPathMatcher
The PathMatcher for Ant-style patterns, the syntax of locations such as classpath*:i18n/**/*.properties.
ByteArrayResource
A resource over bytes held in memory.
ClasspathResources
The registry behind classpath: locations: the files of lib/resources/ of the application and of its dependencies.
CompositePropertySource
One property source made of several others, asked in order.
ConfigDataEnvironment
Reads the application's config files (application.properties, application.yml and their profile variants, imports, config trees) into an environment and sets the active profiles they name.
ConfigurableEnvironment
An Environment that can be changed: its list of property sources, its profiles and how it converts and resolves values.
ConfigurablePropertyResolver
A PropertyResolver whose behaviour can be set: the conversion service, the placeholder syntax, and keys that must be present.
ConfigurationPropertyName
A property name split into its elements (app, read-timeout) and compared the relaxed way, so app.readTimeout, app.read_timeout and app.read-timeout are the same name.
ConfigurationPropertySources
Makes an environment find a property however a source spells it: a read of app.read-timeout also finds app.readTimeout, app.read_timeout or the variable APP_READTIMEOUT.
ConfigurationPropertySourcesPropertySource
The property source that ConfigurationPropertySources.attach puts first in an environment, so reads of a property find it under any spelling.
ConversionService
Turns a value into a value of another type, such as the text '10s' from a config file into a Duration.
ConverterRegistry
The part of a conversion service that accepts new converters.
DataSize
An amount of data, such as an upload limit or a cache size, stored as a whole number of bytes.
DefaultConversionService
A conversion service that already knows the types configuration values are usually read as: numbers, booleans, durations, data sizes, URIs, dates, encodings, resources and lists, sets and maps of them.
DefaultPropertySourceFactory
The factory @PropertySource uses when none is named: it reads the file as .properties.
DefaultResourceLoader
The ResourceLoader used everywhere: it knows classpath:, file:, http:, https: and package: locations, plus any prefix taught by a ProtocolResolver.
DescriptiveResource
A resource that never exists, standing for a location that cannot be resolved.
DurationStyle
Reads and writes durations as text, in the two forms configuration files use: the short form 10s and ISO-8601 PT10S.
EmbeddedResource
The content of one file of lib/resources/, written into the generated code at build time.
EncodedResource
A resource paired with the character encoding to read it in; null means UTF-8.
EnumerablePropertySource<T extends Object>
A property source that can list every key it has.
Environment
The application's configuration as code sees it: every property from every source (config files, command line, environment variables), and the active profiles.
FileSystemResource
A Resource for a file (or directory) on the local file system, given by its path.
FunctionProtocolResolver
A ProtocolResolver made from a function, for a resolver too small to deserve a class.
GenericConversionService
A conversion service that starts empty and converts only what is registered on it.
InMemoryProtocolResolver
A ProtocolResolver that serves prefix:path locations from a map of paths to text held in memory.
Log
An annotation that gives a class a ready-made log getter, so its methods can log without declaring a logger.
LogFormatUtils
Formats values for log lines: what the framework writes about values from outside (a path, a user name, a header) goes through it.
MapPropertySource
A property source over a map of keys to values.
MutablePropertySources
The ordered list of property sources an environment reads from; for each key, the first source that has it wins.
Order
An annotation that gives a bean (or a @Bean method, an event listener method) its place when several are run or injected in turn; lower values come first.
OrderComparator
Sorts objects the way the framework does: PriorityOrdered first, then by order value, objects with equal values keeping their original order.
Ordered
An object that says where it goes when several objects of its kind are run or listed in turn; lower numbers come first.
PathMatcher
Tests paths such as config/dev/app.properties against patterns with wildcards such as config/**/*.properties, and pulls values out of them.
PathMatchingResourcePatternResolver
The ResourcePatternResolver used everywhere: it expands Ant-style patterns (*, **, ?) in file: and classpath locations.
Principal
The identity of whoever makes a request: a user, a client application or another service, reduced to a name.
PriorityOrdered
An Ordered object that goes before every plain Ordered one, whatever the numbers.
Profiles
A condition on profiles, such as "dev, and eu or us", parsed once and tested against the active profiles.
PropertiesLoaderUtils
Reads a .properties Resource into a map of keys to values in one call.
PropertiesParser
Reads text in the .properties format (key=value lines) into a map.
PropertiesPropertySourceLoader
The reader for .properties config files, used for application.properties and its profile variants.
PropertyPlaceholderHelper
The engine that replaces ${name} and ${name:default} placeholders in text, looking each name up with a function you give.
PropertyResolver
Reading properties by key: as text or as a typed value, with or without a default, and resolving ${...} placeholders in any text.
PropertySourceFactory
Turns a file named in @PropertySource into a property source; write one to let @PropertySource read a format other than .properties.
PropertySourceLoader
A reader for one config file format: it turns the text of a file into property sources, one per document in the file.
PropertySourceProcessor
The code that reads the files of @PropertySource annotations into an environment.
PropertySourcesPropertyResolver
The property resolver that reads from a list of property sources, the first source with a non-null value winning.
ProtocolResolver
A plug-in that teaches a resource loader a location prefix of its own, such as asset: or db:.
RandomValuePropertySource
A property source that makes up a new random value for every key that starts with random..
Resource
A piece of content the application reads, wherever it lives: a file of lib/resources/ (the classpath), a file on disk, a URL, a Flutter asset, bytes in memory.
ResourceLoader
Turns a location string such as classpath:mail.txt, file:./data.csv or https://... into a Resource to read.
ResourcePatternResolver
A ResourceLoader that also finds all resources matching a pattern with wildcards, such as classpath:templates/*.html or file:config/**/*.properties.
ResourcePropertySource
A property source with the properties of one .properties file.
SimpleCommandLinePropertySource
The property source over the program's command-line arguments, so that --server.port=9090 sets the property server.port.
SpringLog
A named logger: the object code logs through, and the static switches (levels, handler, holds) of logging as a whole.
SpringLogHold
The records held back by one SpringLog.hold, until release.
SpringLogRecord
One logged message with everything known about it, as a log handler receives it.
StandardEnvironment
The environment implementation used everywhere: an empty list of property sources except the environment variables, plus profiles.
SystemEnvironmentPropertySource
The property source over the operating system's environment variables, which finds server.port in the variable SERVER_PORT.
UrlResource
A Resource on a web server, read with an HTTP GET request.
YamlPropertySourceLoader
The reader for YAML config files (.yml, .yaml), used for application.yml and its profile variants.

Enums

ChronoUnit
A unit of time, from nanoseconds to days: the unit in which a plain number is read as a duration.
CloudPlatform
A cloud platform an application can run on (Kubernetes, Heroku, Cloud Foundry, ...), recognised from the environment variables the platform sets.
ConfigurationPropertyNameForm
How an element of a ConfigurationPropertyName is returned by ConfigurationPropertyName.getElement: as written, dashed or reduced to letters and digits. Bracketed elements are always returned as written.
DataUnit
A unit a DataSize can be written in, each 1024 times the one before.
SpringLogLevel
How important a log message is, from trace (most detail) to error; off silences a logger.

Properties

printLogHandlerColours ↔ bool
Whether printLogHandler colours its lines with ANSI escape codes.
getter/setter pair
printLogHandlerOut ↔ void Function(String line)
Where printLogHandler writes its lines: standard output on the Dart VM, print in Flutter (the device log) and on the web (the browser's console). Replace it to send them elsewhere, or in a test of the output.
getter/setter pair

Functions

parseSpringLogLevel(String? value) → SpringLogLevel?
Reads a level name as written in configuration (logging.level.*): trace, debug, info, warn or warning, error (also fatal) and off, in any case and with spaces around. null for anything else, so the caller can report the bad value.
printLogHandler(SpringLogRecord record) → void
The SpringLog.handler used until a logging backend replaces it: writes each record as one line, [logger] LEVEL: message, to standard output on the Dart VM, to the device log in Flutter and to the browser's console on the web.

Typedefs

SpringLogHandler = void Function(SpringLogRecord record)
A function that receives log records: the type of SpringLog.handler (where records go) and of SpringLog.listen listeners.

Exceptions / Errors

ConfigDataLoadException
The startup error for config data that exists but cannot be used.
ConfigDataLocationNotFoundException
The startup error for a required directory location that does not exist, such as spring.config.import=file:./config/ without a ./config/ directory.
ConfigDataResourceNotFoundException
The startup error for a config file that must exist and does not, such as spring.config.import=file:./secrets.yml when there is no secrets.yml.
ConversionException
The error a conversion service throws when a value cannot be turned into the requested type.
ConversionFailedException
The conversion error for a value the converter could not handle, such as '12x' for an int.
ConverterNotFoundException
The conversion error for a target type that nothing converts to, or a source that no converter of that target accepts.
InvalidConfigDataPropertyException
The startup error for a property written in a config file where it is not allowed.
InvalidConfigurationPropertyNameException
The error for a name that should be canonical and is not, such as a @ConfigurationProperties prefix written app.readTimeout instead of app.read-timeout.
MissingPropertyException
The error for a property read as required that no source has.
MissingRequiredPropertiesException
The error for properties that were declared required and have no value.
PlaceholderResolutionException
The error for a ${...} placeholder that has no value and no default, or that refers to itself in a loop (a=${b}, b=${a}).
PropertySourceNotFoundException
The startup error for a file named in @PropertySource that does not exist.