使用 Ribbon,如果您想对特定服务使用自定义 ServerList
实现而不是默认的 ConfigurationBasedServerList
,您可以在应用程序配置文件中这样做:
my-service:
ribbon:
NIWSServerListClassName: com.myapp.MyCustomServerList
我的问题是,我想替换我声明使用 MyCustomServerList
的所有服务的默认 ConfigurationBasedServerList
。
我可以为每个服务添加以前的属性 block ,但这可能会无限增长。
有没有办法将 MyCustomServerList
声明为默认值?
我还尝试将此 bean 添加到我的 @Configuration
类中,但它似乎只在我第一次发出请求时才起作用:
@Bean
public ServerList<Server> ribbonServerList() {
return new MyCustomServerList();
}
最佳答案
参见http://cloud.spring.io/spring-cloud-static/Dalston.SR1/#_customizing_the_ribbon_client
@RibbonClients(defaultConfiguration=MyConfig.class)
//...
class MyConfig {
@Bean
public ServerList<Server> ribbonServerList() {
return new MyCustomServerList();
}
}
关于java - 替换所有服务的 ConfigurationBaseServerList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44179122/