ConditionalOnExpression class
Registers a bean only when an expression evaluates to true.
For a rule the other conditions cannot express, such as a combination
of several properties. The expression is in SpEL, the expression
language of spring_core_dart; ${...} placeholders are replaced by
property values first. It may be written with or without #{...} and
is evaluated with the bean factory's expression resolver, so it can
refer to environment and to beans registered so far. A null result
counts as false; any other non-boolean result fails the start.
Prefer ConditionalOnProperty when it is enough: it is easier to read.
// Only when caching is on (the default) and the shop runs in the EU.
@Bean()
@ConditionalOnExpression(r"${app.cache:true} and '${app.mode}' == 'eu'")
Cache cache() => Cache();
Spring (Java):
@ConditionalOnExpression("${app.cache:true} and '${app.mode}' == 'eu'").
- Implemented types
Constructors
- ConditionalOnExpression([String expression = 'true'])
-
Checks
expression; without one it always matches.const
Properties
- expression → String
-
The SpEL expression that must give
true, with or without#{...}.final - hashCode → int
-
The hash code for this object.
no setterinherited
- 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