org.zodiac.autoconfigure.bootstrap.discovery.composite.CompositeAppDiscoveryClientAutoConfiguration Maven / Gradle / Ivy
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);
}
}