ConditionalOnBooleanProperty class
Registers a bean only when a true / false property has the wanted
value.
It is the plain way to write an on/off switch such as
app.metrics.enabled. Unlike ConditionalOnProperty, the value is
read as a boolean: a value that is not a boolean fails the start
instead of silently counting as "set".
// Metrics only with app.metrics.enabled=true.
@Bean()
@ConditionalOnBooleanProperty('app.metrics.enabled')
Metrics metrics() => Metrics();
// On by default; app.audit.enabled=false turns it off.
@Bean()
@ConditionalOnBooleanProperty('app.audit.enabled', matchIfMissing: true)
Audit audit() => Audit();
Spring (Java): @ConditionalOnBooleanProperty("app.metrics.enabled").
- Implemented types
Constructors
- ConditionalOnBooleanProperty(String name, {String prefix = '', bool havingValue = true, bool matchIfMissing = false})
-
Checks the property
name(afterprefix). By default it matches when the property istrue.const -
ConditionalOnBooleanProperty.names(List<
String> names, {String prefix = '', bool havingValue = true, bool matchIfMissing = false}) -
Checks every property of
names(each afterprefix); all of them must match.const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- havingValue → bool
-
The value that matches;
trueby default. Usefalsefor a bean that replaces a feature when it is switched off.final - matchIfMissing → bool
-
Whether a property that is not set matches; false by default.
final
- name → String?
-
The property checked, when the unnamed constructor was used; null
with ConditionalOnBooleanProperty.names.
final
-
names
→ List<
String> -
The properties checked with ConditionalOnBooleanProperty.names;
empty with the unnamed constructor.
final
- prefix → String
-
Put before each name, so
prefix: 'app'with'enabled'checksapp.enabled. Empty by default.final -
propertyNames
→ List<
String> -
The full names of the checked properties, with prefix applied.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
matches(
ConditionContext context) → bool -
Whether the annotated bean should be registered;
contextgives access to the configuration and the definitions registered so far.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited