简体   繁体   English

自定义 DiscoveryClient 用于发现 Spring 云配置服务器

[英]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.

相关问题 带有配置服务器的 Spring Cloud Eureka - Spring Cloud Eureka with Config Server Spring 云 DiscoveryClient。 getLocalServiceInstance() 已弃用,如何使用注册? - Spring cloud DiscoveryClient. getLocalServiceInstance() deprecated, how to use Registration? 当 Spring Security 在 Spring Cloud Config Server 上处于活动状态时,Spring Cloud Config Client 不获取配置 - Spring Cloud Config Client not fetching config when Spring Security is active on Spring Cloud Config Server Spring Cloud Config Server环境变量的优先级 - Spring Cloud Config Server Priority of Environment Variables Spring Cloud Config Server无法解析占位符 - Spring Cloud Config Server Could not resolve placeholder Spring Cloud Config Server: error: No such label: master - Spring Cloud Config Server: error: No such label: master Spring 云配置服务器 ssh 到 bitbucket 问题 - Spring cloud config server ssh to bitbucket problem 配置Spring Cloud Config Server和Spring Cloud Vault以进行生产 - Configuring Spring Cloud Config Server and Spring Cloud Vault for production Spring Cloud Config服务器显示invalidPrivateKey - Spring Cloud Config server showing invalidPrivateKey 带有 Azure KeyVault 后端的 Spring Cloud Config Server - Spring Cloud Config Server with Azure KeyVault backend
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM