ConditionalOnPod class
An annotation that conditionally activates a Component, Pod, or configuration class based on the presence of other pods within the current ConditionalContext.
The ConditionalOnPod annotation enables declarative control over component initialization in JetLeaf. It allows you to specify which pods must already exist before the annotated construct can be loaded. This promotes modular, dependency-aware configuration and prevents the unnecessary creation of components whose prerequisites are unavailable.
Purpose
In modular JetLeaf applications, some components should only initialize when certain dependencies (pods) are present. Instead of manually checking for these dependencies at runtime, ConditionalOnPod provides a declarative and type-safe mechanism to:
- Express dependencies on other pods (by name or type).
- Prevent activation when dependencies are missing.
- Support clean, composable configuration layers that activate dynamically based on contextual availability.
Behavior
- values can include either pod names (
String) or types (Type,ClassType, or fully qualified class names). - During evaluation, JetLeaf checks whether all specified pods are present in the ConditionalContext.
- If any required pod is missing, the annotated element is skipped silently, ensuring graceful degradation.
Example
// Activate only if a DataSource pod is registered
@ConditionalOnPod([ClassType<DataSource>()])
class JdbcTemplateConfig {}
// Activate only if a pod named 'myCustomService' exists
@ConditionalOnPod(['myCustomService'])
class FallbackServiceConfig {}
// Activate only if both a type and name condition are satisfied
@ConditionalOnPod([ClassType<Cache>(), 'metricsService'])
class CachedMetricsConfig {}
Related Components
- ConditionalContext — Evaluates pod availability and manages conditional initialization.
- Conditional — The base conditional annotation that ConditionalOnPod extends for contextual activation logic.
ClassType— Represents type references for type-safe pod checks.
- Inheritance
-
- Object
- WhenConditional
- ConditionalOnPod
- Annotations
-
- @Conditional([OnPodCondition()])
- @Target.new({TargetKind.classType, TargetKind.method})
Constructors
-
ConditionalOnPod([List<
Object> values = const []]) -
An annotation that conditionally activates a Component, Pod, or
configuration class based on the presence of other pods within the
current ConditionalContext.
const
Properties
- annotationType → Type
-
Returns the annotation _type of this annotation.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
values
→ List<
Object> -
Specifies pods that must be present in the ConditionalContext
for the annotated component to activate.
final
Methods
-
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode, andtoString. -
equals(
Object other) → bool -
Checks whether the given object is logically equivalent to this annotation.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String - Returns a string representation of this annotation.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited