OnPropertyCondition class
A Condition implementation that evaluates whether a component or pod should be activated based on the presence and value of properties in the current ConditionalContext.environment.
OnPropertyCondition is typically used in conjunction with the ConditionalOnProperty annotation, which specifies property names, optional prefixes, expected values, and whether missing properties should still allow activation.
Behavior
- If the annotated element does not have a ConditionalOnProperty annotation, this condition automatically passes.
- Retrieves the annotation from the source using
Annotation.getDirectAnnotation. - For each property name:
- Combines the optional
prefixwith the property name to form the full key. - Retrieves the property's value from
environment.getProperty. - If the property is missing:
- Passes if
matchIfMissingistrue. - Fails if
matchIfMissingisfalse.
- Passes if
- If
havingValueis specified, the property's value must match (case-insensitive) to pass. - If
havingValueis not specified, any value equal to"false"causes the condition to fail.
- Combines the optional
- Logs trace information at every evaluation step if logging is enabled.
Example
@ConditionalOnProperty(
prefix: 'server',
names: ['ssl.enabled', 'ssl.enabled2'],
havingValue: 'true',
matchIfMissing: false,
)
class SslServerConfig {}
// During context evaluation:
final context = ConditionalContext(environment, podFactory, runtimeProvider);
final condition = OnPropertyCondition();
final shouldActivate = await condition.matches(context, source);
Logging
Trace logging provides detailed step-by-step information:
- Annotation presence and retrieval.
- Property key resolution and value checks.
- Pass/fail decisions for each property.
Related Components
- ConditionalContext: Provides access to environment properties and other conditional evaluation data.
- ConditionalOnProperty: Annotation that defines the properties to evaluate for conditional activation.
- Annotation: The metadata source of the annotated element.
- Implemented types
Constructors
- OnPropertyCondition()
-
A Condition implementation that evaluates whether a component or pod
should be activated based on the presence and value of properties
in the current ConditionalContext.environment.
const
Properties
- 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(
ConditionalContext context, Annotation annotation, Source source) → Future< bool> -
Evaluates the condition against the given ConditionalContext and
annotationfor the specified Source.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