[英]Custom DiscoveryClient for to discover Spring Cloud Config server
我正在尝试构建自己的DiscoveryClient
,它将使用 Docker Swarm 作为服务源。 我已经使用 Spring 云网关和 Spring 云负载均衡器。 但是,当我尝试通过设置configserver
spring.cloud.config.discovery.enabled=true
来使用它为配置服务器进行发现时,我收到以下错误
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.client.discovery.DiscoveryClient' available: expected at l
east 1 bean which qualifies as autowire candidate. Dependency annotations: {}
我也创建了 AutoConfigure 类,但没有运气。 项目在这里https://github.com/trajano/spring-cloud-demo 。
查看调试日志时,无论是否发现, AutoConfiguration
bean 似乎都没有加载到CONDITIONS EVALUATION REPORT中,特别是其他库中的那些。
类似于Spring 云发现首先根本不起作用,但他们正在使用 Eureka,而我正在尝试确定如何构建自己的 DiscoveryClient。
我看到您的 DiscoveryClient 配置 class有以下注释:
@ConditionalOnDiscoveryEnabled
@ConditionalOnBlockingDiscoveryEnabled
@ConditionalOnDockerSwarmDiscoveryEnabled
@AutoConfigureAfter({
DockerSwarmDiscoveryAutoConfiguration.class
})
@AutoConfigureBefore({
SimpleDiscoveryClientAutoConfiguration.class,
CommonsClientAutoConfiguration.class
})
难道是那些设置没有启用? 你提到你启用了发现,但你没有提到其他 ConditionOnX 配置。 如果它们未启用,则 bean 将不会加载。
spring.factory
中有一组单独的org.springframework.boot.autoconfigure.EnableAutoConfiguratio
元素,称为org.springframework.cloud.bootstrap.BootstrapConfiguration
所以我添加了这个
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
net.trajano.spring.swarm.discovery.DockerSwarmDiscoveryClientConfigServiceBootstrapConfiguration
还有这个 class
@ConditionalOnClass(ConfigServicePropertySourceLocator.class)
@ConditionalOnProperty("spring.cloud.config.discovery.enabled")
@Configuration(proxyBeanMethods = false)
@Import({
DockerSwarmDiscoveryClientAutoConfiguration.class,
// this emulates
// @EnableDiscoveryClient, the import
// selector doesn't run before the
// bootstrap phase
DockerClientConfiguration.class,
DockerSwarmDiscoveryAutoConfiguration.class,
DockerSwarmReactiveDiscoveryClientAutoConfiguration.class,
ReactiveCommonsClientAutoConfiguration.class
})
public class DockerSwarmDiscoveryClientConfigServiceBootstrapConfiguration {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.