Spring boot 在application.properties中按服务名称为@FeignClient提供URL,但不带负载平衡器
我想使用外部客户端,并按服务名称在Spring boot 在application.properties中按服务名称为@FeignClient提供URL,但不带负载平衡器,spring-boot,spring-cloud,spring-cloud-feign,feign,netflix-ribbon,Spring Boot,Spring Cloud,Spring Cloud Feign,Feign,Netflix Ribbon,我想使用外部客户端,并按服务名称在application.properties中提供URL 先决条件: 我使用Spring Boot,并且我依赖于Spring Cloud: <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </depend
application.properties
中提供URL
先决条件:
我使用Spring Boot,并且我依赖于Spring Cloud:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
尝试:
1.代码中的硬编码URL
我知道如何在代码中使用核心URL:
@FeignClient(name = "some-service", url = "http://some-service.com/")
public interface SomeServiceClient {}
但我想使用属性文件
2.硬编码属性
我知道如何硬编码属性以从属性读取URL:
@FeignClient(name = "some-service", url = "${some-service.url}")
public interface SomeServiceClient {}
application.properties
:
some-service.url=http://some-service.com/
some-service.ribbon.listOfServers=http://some-service.com/
ribbon.eureka.enabled=false
这是一个更好的方法,但我想将属性名与假客户端分离。我只想使用名称
3.带负载平衡器的功能区
我知道,当我可以为Ribbon的负载平衡器指定URL列表(通过假客户端名称)时,SpringCloud提供了Ribbon
@FeignClient(name = "some-service")
public interface SomeServiceClient {}
application.properties
:
some-service.url=http://some-service.com/
some-service.ribbon.listOfServers=http://some-service.com/
ribbon.eureka.enabled=false
注意:我必须禁用Eureka(默认启用),因为我不需要Eureka服务器。我需要在我的应用程序中的application.properties
中提供URL
依赖关系:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
我不需要负载平衡器(我只有一个URL)。如何禁用它并始终首先获取服务器列表
?也许有一种方法可以提供负载平衡器的定制实现?或者至少禁用冗余负载平衡器的日志
或者如何以其他方式为服务名称配置一个URL
我阅读了文档,但没有找到解决方案:
- 我面临同样的问题,您是否按照中的建议尝试了以下方法
spring.main.allow-bean-definition-overriding=true
feign.client.config.some-service.url=http://some-service.com/