PropertiesPropertySourceLoader class final
The reader for .properties config files, used for
application.properties and its profile variants.
A file can hold several documents, separated by a line #--- or
!---; each becomes its own property source, so a later document can
be limited to a profile. The config data loader uses it by default, so
applications only write the files. Create one only to read
.properties files in another encoding.
final sources = const PropertiesPropertySourceLoader().load(
'application.properties',
'a=1\n#---\nspring.config.activate.on-profile=dev\na=2\n',
);
sources.length; // 2
// Files in ISO-8859-1, as Spring Boot reads them:
ConfigDataEnvironment(
environment,
loaders: const [PropertiesPropertySourceLoader(encoding: latin1)],
);
Files are read as Spring Boot's OriginTrackedPropertiesLoader reads
them, not as java.util.Properties (PropertiesParser, behind
@PropertySource and message bundles): a key ending in [] is a
comma-separated list (hosts[]=a,b sets hosts[0] and hosts[1]),
an empty key is skipped, and a separator counts only where a new
logical line starts: at the start of a physical line, without leading
blanks, three hyphens and nothing but blanks after them, not right
after a comment line with the same prefix (# note then #--- is two
comments), and not on a line continued from the one before
(a=base\ then #--- sets a to base#---). Two differences from
Boot, which corrupt a file silently there: a comment right after a
separator (before the document's first key) keeps the documents apart
(Boot joins the new document to the one before it), and blanks after
a separator's hyphens do not change how the next line is read (in
Boot, the next line's leading blanks then make it a key without a
name, which is dropped, and a separator there is not seen).
Spring Boot reads .properties files as ISO-8859-1; here they are
UTF-8 unless encoding says otherwise, or the location names an
encoding (x.properties[encoding=iso-8859-1], encodingFor). A
leading byte order mark is skipped. Spring Boot keeps it: read as
ISO-8859-1, its default, the first key starts with  there, and
its relaxed lookup still finds the key (a=bom reads bom in both).
Spring (Java):
List<PropertySource<?>> sources = new PropertiesPropertySourceLoader()
.load("application.properties",
new ClassPathResource("application.properties"));
- Inheritance
-
- Object
- PropertySourceLoader
- PropertiesPropertySourceLoader
Constructors
- PropertiesPropertySourceLoader({Encoding encoding = utf8})
-
Creates a loader that decodes files with
encoding, UTF-8 unless given.const
Properties
- encoding → Encoding
-
The character encoding the files are decoded with before load;
UTF-8 unless overridden.
final
-
fileExtensions
→ List<
String> -
The file extensions this loader reads, without the dot (
json). When several loaders claim one, the first in the list wins.no setteroverride - hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
encodingFor(
Encoding hint) → Encoding -
hint: a.propertiesfile is decoded with the encoding its location names, as in Spring Boot.override -
load(
String name, String content) → List< AbstractPropertySource< Object> > -
Parses
content, the text of one file, into one property source per document, in file order, skipping empty documents. Keys must be flat (server.port), as in a.propertiesfile.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 -
The equality operator.
inherited