W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
在某些情況下,您可能需要自定義來自客戶端對配置服務(wù)器的請求。通常,這樣做涉及傳遞特殊的?Authorization
?標頭以驗證對服務(wù)器的請求。提供自定義?RestTemplate
?:
1. 創(chuàng)建一個新的配置bean,實現(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)建一個名為?spring.factories
?的文件并指定您的自定義配置,如以下示例所示:
spring.factories.
org.springframework.cloud.bootstrap.BootstrapConfiguration = com.my.config.client.CustomConfigServiceBootstrapConfiguration
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: