W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
您可以使用<client>.ribbon.*
中的外部屬性來配置Ribbon客戶端的某些位,這與本地使用Netflix API相似,不同之處在于可以使用Spring Boot配置文件??梢詫⒈緳C(jī)選項檢查為CommonClientConfigKey
(功能區(qū)核心的一部分)中的靜態(tài)字段。
Spring Cloud還允許您通過使用@RibbonClient
聲明其他配置(在RibbonClientConfiguration
之上)來完全控制客戶端,如以下示例所示:
@Configuration @RibbonClient(name = "custom", configuration = CustomConfiguration.class) public class TestConfiguration { }
在這種情況下,客戶端由RibbonClientConfiguration
中已有的組件以及CustomConfiguration
中的任何組件組成(其中后者通常會覆蓋前者)。
CustomConfiguration
類必須是@Configuration
類,但請注意,對于主應(yīng)用程序上下文,它不在@ComponentScan
中。否則,它由所有@RibbonClients
共享。如果您使用@ComponentScan
(或@SpringBootApplication
),則需要采取措施避免將其包括在內(nèi)(例如,可以將其放在單獨(dú)的,不重疊的程序包中,或指定要在@ComponentScan
)。
下表顯示了Spring Cloud Netflix默認(rèn)為Ribbon提供的beans:
Bean類型 | Bean名稱 | 班級名稱 |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
創(chuàng)建其中一種類型的bean并將其放置在@RibbonClient
配置中(例如上述FooConfiguration
),您可以覆蓋所描述的每個beans,如以下示例所示:
@Configuration protected static class FooConfiguration { @Bean public ZonePreferenceServerListFilter serverListFilter() { ZonePreferenceServerListFilter filter = new ZonePreferenceServerListFilter(); filter.setZone("myTestZone"); return filter; } @Bean public IPing ribbonPing() { return new PingUrl(); } }
上一示例中的include語句將NoOpPing
替換為PingUrl
,并提供了自定義serverListFilter
。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: