Feign + Consul:只启用发现(客户端),不启用注册(服务)

Feign + Consul: Enable only discovery (client), not registration (service)

引用 docs:

@EnableDiscoveryClient make the app into both a Consul "service" (i.e. it registers itself) and a "client" (i.e. it can query Consul to locate other services).

如何配置 Spring 引导应用程序,它使用 Feign 作为 REST 客户端并在 Consul 中查找服务实例,但不在 Consul 中注册应用程序本身?

我试过了:

一个。

的各种组合
spring.cloud.consul.enabled = true
spring.cloud.consul.discovery.enabled = true

b。根本不使用注释,只使用

@EnableFeignClients
// @EnableDiscoveryClient

在调用过程中产生异常:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ribbonServerList' defined in org.springframework.cloud.consul.discovery.ConsulRibbonClientConfiguration: Unsatisfied dependency expressed through method 'ribbonServerList' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

我的FeingClient界面是这样注释的:

@FeignClient(value = "test-service")

其中 test-service 是在 Consul 中成功注册的服务。

你应该使用 @EnableDiscoveryClient(autoRegister=false).