Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring cloud 无法使用服务器列表配置@FeignClient_Spring Cloud_Spring Cloud Netflix_Netflix Feign_Netflix Ribbon - Fatal编程技术网

Spring cloud 无法使用服务器列表配置@FeignClient

Spring cloud 无法使用服务器列表配置@FeignClient,spring-cloud,spring-cloud-netflix,netflix-feign,netflix-ribbon,Spring Cloud,Spring Cloud Netflix,Netflix Feign,Netflix Ribbon,我无法为@FeignClient配置要使用的服务器列表。我使用的是Spring Cloud Netflix,但是这个特定的服务(foo服务)没有在Eureka注册。因此,我需要在YML文件中为foo服务配置服务器列表 但是,listOfServers从未被读取,因此操作失败,因为Feign/Ribbon没有一台服务器可供使用 我做错了什么 我的假客户: @FeignClient(name=“foo服务”) 公共接口FooFeignClient{ @RequestMapping(value=“/p

我无法为
@FeignClient
配置要使用的服务器列表。我使用的是Spring Cloud Netflix,但是这个特定的服务(
foo服务
)没有在Eureka注册。因此,我需要在YML文件中为
foo服务
配置服务器列表


但是,
listOfServers
从未被读取,因此操作失败,因为Feign/Ribbon没有一台服务器可供使用

我做错了什么

我的假客户:

@FeignClient(name=“foo服务”)
公共接口FooFeignClient{
@RequestMapping(value=“/perform check”,method=POST)
响应性能检查(FooRequest FooRequest);
}
在bootstrap.yml中:

foo服务:
功能区:
尤里卡:
已启用:false
服务器列表:foobox1、foobox2、foobox3
如何在Spring引导应用程序中配置外部客户端:

@springboot应用程序
@启用EUREKACLIENT
@EnableDiscoveryClient
@EnableHazelcastClient
@启用伪装客户端
@带状客户({
@RibbonClient(name=“foo服务”,配置=MyApp.FooServiceRibbonConfig.class)
})
公共类MyApp{
公共静态void main(字符串[]args){
运行(MyApp.class,args);
}
....
@配置
静态类FooServiceRibbonConfig{
@豆子
@条件性缺豆
公共IClientConfig ribbonClientConfig(){
DefaultClientConfigImpl config=新建DefaultClientConfigImpl();
config.loadProperties(“foo服务”);
返回配置;
}
@豆子
服务器列表功能区服务器列表(IClientConfig配置){
ConfigurationBasedServerList serverList=新的ConfigurationBasedServerList();
serverList.initWithNiwsConfig(config);
返回服务器列表;
}
}
}

实现您需求的最简单方法是

在代码中,删除与
FooServiceRibbonConfig
相关的所有代码,如下所示

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableHazelcastClient
@EnableFeignClients
})
public class MyApp {

   public static void main(String[] args) {
      SpringApplication.run(MyApp.class, args);
   }
   ....
}
然后更改您的配置文件,如下所示

foo-service:
   ribbon:
      NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList
      listOfServers: foobox1,foobox2,foobox3

像您那样定义
ribbonServerList
bean是实现这一点的另一种方法,我不知道为什么您的代码没有运行。在我的例子中,类似于您的代码工作得很好。但是有一个更简单的方法,所以请尝试一下

实现您需求的最简单方法是

在代码中,删除与
FooServiceRibbonConfig
相关的所有代码,如下所示

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableHazelcastClient
@EnableFeignClients
})
public class MyApp {

   public static void main(String[] args) {
      SpringApplication.run(MyApp.class, args);
   }
   ....
}
然后更改您的配置文件,如下所示

foo-service:
   ribbon:
      NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList
      listOfServers: foobox1,foobox2,foobox3

像您那样定义
ribbonServerList
bean是实现这一点的另一种方法,我不知道为什么您的代码没有运行。在我的例子中,类似于您的代码工作得很好。但是有一个更简单的方法,所以请尝试一下

listofserver
区分大小写,应该是
listofserver
@spencergib
listofserver
也不起作用。我试图遵循这里的建议,您需要提供一个重新创建问题的示例项目。@Spencergib我仍然有与作者相同的问题。如果可以的话,下面是一个重现错误的示例项目:当您执行
DemoServiceTest
时,应该会看到此消息:
负载平衡器没有可用于客户端的服务器:demoservice
listOfServers
区分大小写,应该是
listOfServers
@Spencergib
listOfServers
没有也可以。我试图遵循这里的建议,您需要提供一个重新创建问题的示例项目。@Spencergib我仍然有与作者相同的问题。如果可以的话,下面是一个复制错误的示例项目:当您执行
DemoServiceTest
时,应该会看到此消息:
负载平衡器没有可用于客户端的服务器:demoservice
我得到相同的异常:
java.lang.RuntimeException:com.netflix.client.ClientException:Load balancer没有可用的服务器客户端服务器:foo服务
。这就好像根本没有读取YML文件一样。我得到了相同的异常:
java.lang.RuntimeException:com.netflix.client.ClientException:Load balancer没有可用于客户端的服务器:foo服务
。就好像根本没有读取YML文件一样。