All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnSpringCloudBootstrapEnabled Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.bootstrap.condition;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.context.annotation.Conditional;
import org.springframework.core.env.ConfigurableEnvironment;
import org.zodiac.commons.util.spring.Springs;

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(ConditionalOnSpringCloudBootstrapEnabled.OnBootstrapEnabledCondition.class)
public @interface ConditionalOnSpringCloudBootstrapEnabled {

    class OnBootstrapEnabledCondition extends AbstractOnBootstrapCondition {

        OnBootstrapEnabledCondition() {
            super(ConditionalOnSpringCloudBootstrapEnabled.class, true);
        }

        @Override
        protected boolean matchCondition(ConfigurableEnvironment environment) {
            return Springs.isSpringCloud(environment);
        }

    }

    // class OnBootstrapEnabledCondition extends AnyNestedCondition {
    //
    // OnBootstrapEnabledCondition() {
    // super(ConfigurationPhase.REGISTER_BEAN);
    // }
    //
    // @Override
    // public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    // ConfigurableEnvironment environment = (ConfigurableEnvironment)context.getEnvironment();
    // /*上下文已经包含Spring Cloud环境属性*/
    // MutablePropertySources propertySources = environment.getPropertySources();
    // if (propertySources.contains(Constants.Spring.SPRING_CLOUD_BOOTSTRAP_PROPERTY_SOURCE_NAME) ||
    // propertySources.contains(Constants.Spring.SPRING_CLOUD_BOOTSTRAP_PROPERTIES_PROPERTY_SOURCE_NAME)) {
    // return super.getMatchOutcome(context, metadata);
    // }
    // /*上下文没有包含Spring Cloud环境属性*/
    // return new ConditionOutcome(false, ConditionMessage.of("AnyNestedCondition did not matched Spring Cloud bootstrap
    // environment."));
    // }
    //
    //
    // @ConditionalOnClass(name = Springs.SPRING_CLOUD_MARKER_CLASS)
    // static class OnBootstrapMarkerClassPresent {
    //
    // }
    //
    // /*from Spring Boot 2.4*/
    // /*
    // @ConditionalOnProperty(name = SystemPropertiesConstants.Spring.SPRING_CONFIG_USE_LEGACY_PROCESSING_PROPERTY)
    // static class OnUseLegacyProcessingEnabled {
    //
    // }
    // */
    //
    // @ConditionalOnProperty(name = SystemPropertiesConstants.Spring.SPRING_CLOUD_BOOTSTRAP_ENABLED)
    // static class OnBootstrapEnabled {
    //
    // }
    //
    // }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy