[英]Custom DiscoveryClient for to discover Spring Cloud Config server
I am trying to build my own DiscoveryClient
that would use Docker Swarm as the service source.我正在尝试构建自己的
DiscoveryClient
,它将使用 Docker Swarm 作为服务源。 I got it working with Spring Cloud Gateway and Spring Cloud Loadbalancer already.我已经使用 Spring 云网关和 Spring 云负载均衡器。 However, when I tried to use it to do discovery for the
configserver
by setting spring.cloud.config.discovery.enabled=true
I get the following error但是,当我尝试通过设置
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: {}
I have created AutoConfigure classes as well but no luck.我也创建了 AutoConfigure 类,但没有运气。 The project is here https://github.com/trajano/spring-cloud-demo .
项目在这里https://github.com/trajano/spring-cloud-demo 。
When looking at the debug logs, with and without the discovery, it appears that the AutoConfiguration
beans do not load up in the CONDITIONS EVALUATION REPORT specifically the ones in other libraries.查看调试日志时,无论是否发现,
AutoConfiguration
bean 似乎都没有加载到CONDITIONS EVALUATION REPORT中,特别是其他库中的那些。
Similar to Spring cloud discovery first does not work at all but they are using Eureka, whereas I am trying to determine how to build my own DiscoveryClient.类似于Spring 云发现首先根本不起作用,但他们正在使用 Eureka,而我正在尝试确定如何构建自己的 DiscoveryClient。
I see your Configuration class for the DiscoveryClient has these annotations:我看到您的 DiscoveryClient 配置 class有以下注释:
@ConditionalOnDiscoveryEnabled
@ConditionalOnBlockingDiscoveryEnabled
@ConditionalOnDockerSwarmDiscoveryEnabled
@AutoConfigureAfter({
DockerSwarmDiscoveryAutoConfiguration.class
})
@AutoConfigureBefore({
SimpleDiscoveryClientAutoConfiguration.class,
CommonsClientAutoConfiguration.class
})
Could it be those settings are not enabled?难道是那些设置没有启用? You mention you enabled discovery, but you do not mention the other ConditionOnX configurations.
你提到你启用了发现,但你没有提到其他 ConditionOnX 配置。 If they are not enabled, the bean would not load.
如果它们未启用,则 bean 将不会加载。
There was a separate set of org.springframework.boot.autoconfigure.EnableAutoConfiguratio
elements in spring.factory
called org.springframework.cloud.bootstrap.BootstrapConfiguration
spring.factory
中有一组单独的org.springframework.boot.autoconfigure.EnableAutoConfiguratio
元素,称为org.springframework.cloud.bootstrap.BootstrapConfiguration
So I added this所以我添加了这个
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
net.trajano.spring.swarm.discovery.DockerSwarmDiscoveryClientConfigServiceBootstrapConfiguration
And this class还有这个 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.