W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
在某些情況下,您可能需要自定義來(lái)自客戶端對(duì)配置服務(wù)器的請(qǐng)求。通常,這樣做涉及傳遞特殊的?Authorization
?標(biāo)頭以驗(yàn)證對(duì)服務(wù)器的請(qǐng)求。提供自定義?RestTemplate
?:
1. 創(chuàng)建一個(gè)新的配置bean,實(shí)現(xiàn)為?PropertySourceLocator
?,如以下示例所示:
CustomConfigServiceBootstrapConfiguration.java
@Configuration
public class CustomConfigServiceBootstrapConfiguration {
@Bean
public ConfigServicePropertySourceLocator configServicePropertySourceLocator() {
ConfigClientProperties clientProperties = configClientProperties();
ConfigServicePropertySourceLocator configServicePropertySourceLocator = new ConfigServicePropertySourceLocator(clientProperties);
configServicePropertySourceLocator.setRestTemplate(customRestTemplate(clientProperties));
return configServicePropertySourceLocator;
}
}
2. 在?resources/META-INF
?中,創(chuàng)建一個(gè)名為?spring.factories
?的文件并指定您的自定義配置,如以下示例所示:
spring.factories.
org.springframework.cloud.bootstrap.BootstrapConfiguration = com.my.config.client.CustomConfigServiceBootstrapConfiguration
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: