替换所有服务的 ConfigurationBasedServerList
Replace ConfigurationBasedServerList for all services
使用 Ribbon,如果你想为特定服务使用自定义 ServerList
实现而不是默认 ConfigurationBasedServerList
,你可以在应用程序配置文件中这样做:
my-service:
ribbon:
NIWSServerListClassName: com.myapp.MyCustomServerList
我的问题是我想为我声明使用 MyCustomServerList
的所有服务替换默认值 ConfigurationBasedServerList
。
我可以只为每个服务添加之前的属性块,但这可能会无限增长。
有没有办法将 MyCustomServerList
声明为默认值?
我也试过将这个 bean 添加到我的 @Configuration
class,但它似乎只在我第一次发出请求时起作用:
@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();
}
}
使用 Ribbon,如果你想为特定服务使用自定义 ServerList
实现而不是默认 ConfigurationBasedServerList
,你可以在应用程序配置文件中这样做:
my-service:
ribbon:
NIWSServerListClassName: com.myapp.MyCustomServerList
我的问题是我想为我声明使用 MyCustomServerList
的所有服务替换默认值 ConfigurationBasedServerList
。
我可以只为每个服务添加之前的属性块,但这可能会无限增长。
有没有办法将 MyCustomServerList
声明为默认值?
我也试过将这个 bean 添加到我的 @Configuration
class,但它似乎只在我第一次发出请求时起作用:
@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();
}
}