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

org.zodiac.autoconfigure.bootstrap.discovery.composite.CompositeAppDiscoveryClientAutoConfiguration Maven / Gradle / Ivy

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

import java.util.List;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnAppDiscoveryEnabled;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnSpringCloudBootstrapDisabled;
import org.zodiac.autoconfigure.bootstrap.discovery.AbstractAppDiscoveryClientConfiguration;
import org.zodiac.autoconfigure.bootstrap.discovery.AppDiscoveryStrategyProperties;
import org.zodiac.autoconfigure.bootstrap.discovery.simple.SimpleAppDiscoveryClientAutoConfiguration;
import org.zodiac.autoconfigure.bootstrap.discovery.simple.SimpleAppDiscoveryProperties;

import org.zodiac.core.bootstrap.discovery.AppDiscoveryClient;
import org.zodiac.core.bootstrap.discovery.composite.CompositeAppDiscoveryClient;

@SpringBootConfiguration
@ConditionalOnAppDiscoveryEnabled
@ConditionalOnSpringCloudBootstrapDisabled
//@EnableConfigurationProperties(value = {AppDiscoveryStrategyProperties.class})
@AutoConfigureBefore(value = {SimpleAppDiscoveryClientAutoConfiguration.class})
public class CompositeAppDiscoveryClientAutoConfiguration extends AbstractAppDiscoveryClientConfiguration {

    private AppDiscoveryStrategyProperties appDiscoveryStrategyProperties;

    public CompositeAppDiscoveryClientAutoConfiguration(AppDiscoveryStrategyProperties appDiscoveryStrategyProperties) {
        this.appDiscoveryStrategyProperties = appDiscoveryStrategyProperties;
    }

    @Bean
    @ConditionalOnMissingBean
    protected SimpleAppDiscoveryProperties simpleAppDiscoveryProperties() {
        return super.simpleAppDiscoveryProperties();
    }

    // @Bean
    // @ConditionalOnMissingBean
    // @Order(Ordered.LOWEST_PRECEDENCE)
    // protected AppDiscoveryClient simpleDiscoveryClient() {
    // return super.simpleDiscoveryClient();
    // }

    @Bean
    @Primary
    //@ConditionalOnMissingBean
    protected CompositeAppDiscoveryClient compositeDiscoveryClient(List discoveryClients) {
        if (discoveryClients.isEmpty()) {
            /*因为该类是在SimpleAppDiscoveryClientAutoConfiguration之前生效,为空说明不是远程服务发现环境,创建基本的客户端。*/
            discoveryClients.add(super.simpleDiscoveryClient());
        }
        return new CompositeAppDiscoveryClient(discoveryClients);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy