Value class
Injects a value from the configuration (properties, environment variables) or from an expression, instead of a bean.
Use it for settings such as a port, a URL or a feature switch.
${key} and ${key:default} placeholders are resolved against the
environment's property sources (config files, environment variables,
command line); #{...} parts are evaluated as SpEL expressions, which
can read other beans. The result is converted to the target type
(int, Duration, List<String>, ...). A nullable target receives
null when a placeholder has no value; a non-nullable one without a
default fails the startup. For a group of related settings, a
@ConfigurationProperties class of spring_boot_dart is often clearer.
Write the value as a raw string (r'...') so that Dart does not read
$ as interpolation.
@Service()
class Server {
// 8080 unless `server.port` is set.
Server(@Value(r'${server.port:8080}') this.port);
final int port;
@Value(r'${server.tags}') // "a,b,c" becomes a list
late final List<String> tags;
@Value('#{appSettings.title.toUpperCase()}') // from the appSettings bean
late final String banner;
}
Spring (Java):
@Service
class Server {
Server(@Value("${server.port:8080}") int port) { ... }
@Value("${server.tags}") List<String> tags;
@Value("#{appSettings.title.toUpperCase()}") String banner;
}
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