OnPodCondition class

A Condition implementation that evaluates the presence or absence of pods in the current ConditionalContext to determine whether a component, configuration, or definition should be activated.

OnPodCondition operates in conjunction with the ConditionalOnPod and ConditionalOnMissingPod annotations. It checks whether specific pods (by type or name) are present or missing in the application’s PodFactory and adjusts component registration accordingly.

Behavior

  • If the annotated element has a ConditionalOnPod annotation:
    • For each required type listed in types, the condition searches the PodFactory for existing pods of that type.
    • For each name listed in names, the condition checks whether a pod with that name exists.
    • The condition fails if any required type or name is not found.
    • The condition passes only if all specified pods exist or are pending registration.
  • If the annotated element has a ConditionalOnMissingPod annotation:
    • For each type in types, the condition checks that no pod of that type exists.
    • For each name in names, the condition verifies that no pod with that name exists.
    • The ignoredTypes list can be used to exclude pods that should not influence this evaluation (such as infrastructure or support pods).
    • The condition passes only if none of the specified pods are registered or queued for registration.
  • If neither annotation is present, the condition automatically passes.

Example

// Activate only if a DataSource pod exists
@ConditionalOnPod(types: [ClassType<DataSource>()])
class JdbcTemplateConfig {}

// Activate only if a remoteCache pod is missing
@ConditionalOnMissingPod(names: ['remoteCache'])
class InMemoryCacheConfig {}

Evaluation Flow

  1. When matches is invoked, OnPodCondition retrieves all unregistered PodDefinition instances from the ConditionalContext.
  2. It evaluates the required pods by checking both the PodFactory registry and unregistered definitions.
  3. If @ConditionalOnPod is present, all required types and names must resolve successfully.
  4. If @ConditionalOnMissingPod is present, all specified pods must be absent or ignored.
  5. The evaluation result determines whether the annotated component or pod definition should proceed with activation.

Logging

  • Provides detailed trace-level logging for each evaluation step.
  • Logs include discovery of annotations, validation of pod types and names, and pass/fail reasons.
  • Trace messages include helpful markers like for success and for failure, assisting in debugging startup conditions.
  • ConditionalContext: Provides runtime access to the environment, PodFactory, and pending PodDefinition instances.
  • ConditionalOnPod: Annotation defining pods that must exist for activation.
  • ConditionalOnMissingPod: Annotation defining pods that must not exist for activation.
  • PodFactory: Manages pod lifecycle and provides lookup operations for existing pods.
  • PodDefinition: Represents an individual pod definition in the system.
  • Annotation: Represents the metadata source of the annotated element.
Implemented types

Constructors

OnPodCondition()
A Condition implementation that evaluates the presence or absence of pods in the current ConditionalContext to determine whether a component, configuration, or definition 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 annotation for 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