【发布时间】:2017-10-17 06:25:13
【问题描述】:
我无法为@FeignClient 配置要使用的服务器列表。我正在使用 Spring Cloud Netflix,但此特定服务 (foo-service) 未在 Eureka 注册。为此,我需要在 YML 文件中为 foo-service 配置服务器列表。
但是,listOfServers 永远不会被读取,因此操作失败,因为 Feign/Ribbon 没有单个服务器可供使用。
我在这里做错了什么?
我的 Feign 客户:
@FeignClient(name="foo-service")
public interface FooFeignClient {
@RequestMapping(value = "/perform-check", method = POST)
ResponseEntity<FooResponse> performCheck(FooRequest fooRequest);
}
在 bootstrap.yml 中:
foo-service:
ribbon:
eureka:
enabled: false
listOfServers: foobox1,foobox2,foobox3
在 Spring Boot 应用中如何配置 Feign 客户端:
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableHazelcastClient
@EnableFeignClients
@RibbonClients({
@RibbonClient(name = "foo-service", configuration = MyApp.FooServiceRibbonConfig.class)
})
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
....
@Configuration
static class FooServiceRibbonConfig {
@Bean
@ConditionalOnMissingBean
public IClientConfig ribbonClientConfig() {
DefaultClientConfigImpl config = new DefaultClientConfigImpl();
config.loadProperties("foo-service");
return config;
}
@Bean
ServerList<Server> ribbonServerList(IClientConfig config) {
ConfigurationBasedServerList serverList = new ConfigurationBasedServerList();
serverList.initWithNiwsConfig(config);
return serverList;
}
}
}
【问题讨论】:
-
listOfServers区分大小写,应为ListOfServers。 -
@spencergibb
ListOfServers也不起作用。我试图听从这里的建议github.com/spring-cloud/spring-cloud-netflix/issues/325 -
您需要提供一个重现问题的示例项目。
-
@spencergibb 我还是和作者一样的问题。如果可以的话,这里是一个重现错误的示例项目:github.com/RaviH/spring-cloud-feign-demo 当您执行
DemoServiceTest时应该会看到此消息:Load balancer does not have available server for client: demoservice
标签: spring-cloud spring-cloud-netflix netflix-feign netflix-ribbon