OnProfileCondition class
A Condition implementation that evaluates the application's currently active profiles to determine whether a component, configuration, or pod should be activated.
OnProfileCondition supports both the Profile and ConditionalOnProfile
annotations. It provides flexible control over pod, and configuration
activation based on environment-specific profiles (e.g., "dev", "test",
"prod").
This condition enables developers to restrict certain components to specific runtime contexts, improving modularity and enabling environment-sensitive configuration in JetLeaf applications.
Behavior
- If the annotated element includes a Profile annotation:
- Each declared profile is compared against the set of active profiles
in the
Environment. - If
negateis false, all specified profiles must be active for the condition to pass. - If
negateis true, all specified profiles must be inactive for the condition to pass. - The condition fails if any profile violates these rules.
- Each declared profile is compared against the set of active profiles
in the
- If the annotated element includes a ConditionalOnProfile annotation:
- The annotation’s
valuelist specifies profiles that must be active in the environment. - If none of the specified profiles are active, the condition fails.
- The condition passes if at least one of the declared profiles is active.
- The annotation’s
- If neither annotation is present, the condition automatically passes.
Example
// Activate only in the 'dev' profile
@ConditionalOnProfile(['dev'])
class DevConfiguration {}
// Exclude this component when 'test' profile is active
@Profile(['test'], negate: true)
class ProductionDatabasePod {}
Evaluation Flow
- When matches is invoked, OnProfileCondition retrieves the currently
active profiles from the
Environment. - If a Profile annotation is present:
- Each listed profile is checked against the active profile set.
- Negation logic is applied if
negate: true.
- If a ConditionalOnProfile annotation is present:
- The condition validates whether any declared profile is active.
- If neither annotation applies, the condition passes automatically.
- The result determines whether the annotated component or configuration should be registered.
Logging
- Detailed trace logs show all evaluated annotations and profiles.
- Logs display active profiles, matched/failed conditions, and negation state.
- Uses icons and structured output for clarity:
✅for successful matches❌for failed evaluations🧩for condition initialization
Related Components
- ConditionalContext: Provides access to the
Environmentand runtime state. - ConditionalOnProfile: Annotation specifying profiles required for activation.
- Profile: Annotation specifying inclusion or exclusion rules for profiles.
Environment: Holds the currently active and default profiles.Annotation: Represents the annotated element under evaluation.
- Implemented types
Constructors
- OnProfileCondition()
-
A Condition implementation that evaluates the application's currently
active profiles to determine whether a component, configuration, or pod
should be activated.
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 specifiedSource.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