Search in sources :

Example 1 with Failure

use of io.micronaut.context.condition.Failure in project micronaut-core by micronaut-projects.

the class AbstractBeanContextConditional method isEnabled.

@Override
public boolean isEnabled(@NonNull BeanContext context, @Nullable BeanResolutionContext resolutionContext) {
    AnnotationMetadata annotationMetadata = getAnnotationMetadata();
    Condition condition = annotationMetadata.hasStereotype(Requires.class) ? new RequiresCondition(annotationMetadata) : null;
    DefaultConditionContext<AbstractBeanContextConditional> conditionContext = new DefaultConditionContext<>((DefaultBeanContext) context, this, resolutionContext);
    boolean enabled = condition == null || condition.matches(conditionContext);
    if (LOG.isDebugEnabled() && !enabled) {
        if (this instanceof BeanConfiguration) {
            LOG.debug(this + " will not be loaded due to failing conditions:");
        } else {
            LOG.debug("Bean [" + this + "] will not be loaded due to failing conditions:");
        }
        for (Failure failure : conditionContext.getFailures()) {
            LOG.debug("* {}", failure.getMessage());
        }
    }
    return enabled;
}
Also used : Condition(io.micronaut.context.condition.Condition) Requires(io.micronaut.context.annotation.Requires) BeanConfiguration(io.micronaut.inject.BeanConfiguration) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) Failure(io.micronaut.context.condition.Failure)

Aggregations

Requires (io.micronaut.context.annotation.Requires)1 Condition (io.micronaut.context.condition.Condition)1 Failure (io.micronaut.context.condition.Failure)1 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)1 BeanConfiguration (io.micronaut.inject.BeanConfiguration)1