DefaultValue class
The value a constructor parameter of a @ConfigurationProperties class
takes when its property is not set.
It is written as a property value would be, so it is converted the
same way: @DefaultValue('10s') for a Duration. Use a String for
a single value and a List<String> for a collection. Without an
argument it gives an empty collection, or a nested object created with
its own defaults rather than null. A Dart default value
({this.port = 8080}) does the same for values that can be const.
@ConfigurationProperties('app')
class AppProperties {
AppProperties(
@DefaultValue('8080') this.port,
@DefaultValue(['a', 'b']) this.hosts,
@DefaultValue() this.pool,
);
final int port;
final List<String> hosts;
final Pool pool;
}
Spring (Java):
public record AppProperties(@DefaultValue("8080") int port,
@DefaultValue({"a", "b"}) List<String> hosts,
@DefaultValue Pool pool) {}
Constructors
- DefaultValue([Object value = const <String>[]])
-
A default of
value: aString, aList<String>, or nothing for an empty collection or a nested object with its own defaults.const
Properties
Methods
-
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