ConfigurationCondition class abstract interface

A Condition decided in one ConfigurationPhase only; plain conditions count in both.

It exists for conditions on other beans. "Is there a Clock bean?" can only be answered once the classes before have registered theirs, so such a condition asks for ConfigurationPhase.registerBean. Spring Boot's @ConditionalOnBean, @ConditionalOnMissingBean and @ConditionalOnSingleCandidate work that way (OnBeanCondition). Application code rarely writes one.

A registerBean condition does not stop a configuration class from being parsed (its property sources load, its selectors run); it decides, when the class is read, whether the class, its @Bean methods and its imports (registrars, selected classes) are registered — one decision for all of them. On a @Bean method it is decided when that method is registered. A scanned or imported component is a lite configuration class: such a condition on it is decided when the component is read, at its place in class order. Only a hand-written definition with neither a source nor a factoryMethodName is decided at once.

// A default clock that steps aside when the application has one.
class OnMissingClock implements ConfigurationCondition {
  const OnMissingClock();

  @override
  ConfigurationPhase get configurationPhase =>
      ConfigurationPhase.registerBean;

  @override
  bool matches(ConditionContext context) =>
      context.beanFactory.getBeanNamesForType(Clock).isEmpty;
}

Spring (Java):

class OnMissingClock implements ConfigurationCondition {
  public ConfigurationPhase getConfigurationPhase() {
    return ConfigurationPhase.REGISTER_BEAN;
  }
  public boolean matches(
      ConditionContext c, AnnotatedTypeMetadata m) { ... }
}
Implemented types

Properties

configurationPhase → ConfigurationPhase
The phase in which the condition is decided; in the other phase it counts as matching.
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

Methods

matches(ConditionContext context) → bool
Whether the annotated bean should be registered; context gives access to the configuration and the definitions registered so far.
inherited
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