Search in sources :

Example 1 with RestTemplateCustomizer

use of org.springframework.boot.web.client.RestTemplateCustomizer in project spring-boot by spring-projects.

the class RestTemplateAutoConfigurationTests method restTemplateShouldApplyCustomizer.

@Test
public void restTemplateShouldApplyCustomizer() throws Exception {
    load(RestTemplateCustomizerConfig.class, RestTemplateConfig.class);
    RestTemplate restTemplate = this.context.getBean(RestTemplate.class);
    RestTemplateCustomizer customizer = this.context.getBean(RestTemplateCustomizer.class);
    verify(customizer).customize(restTemplate);
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) RestTemplateCustomizer(org.springframework.boot.web.client.RestTemplateCustomizer) Test(org.junit.Test)

Example 2 with RestTemplateCustomizer

use of org.springframework.boot.web.client.RestTemplateCustomizer in project spring-boot by spring-projects.

the class RestTemplateAutoConfiguration method restTemplateBuilder.

@Bean
@ConditionalOnMissingBean
public RestTemplateBuilder restTemplateBuilder() {
    RestTemplateBuilder builder = new RestTemplateBuilder();
    HttpMessageConverters converters = this.messageConverters.getIfUnique();
    if (converters != null) {
        builder = builder.messageConverters(converters.getConverters());
    }
    List<RestTemplateCustomizer> customizers = this.restTemplateCustomizers.getIfAvailable();
    if (!CollectionUtils.isEmpty(customizers)) {
        customizers = new ArrayList<>(customizers);
        AnnotationAwareOrderComparator.sort(customizers);
        builder = builder.customizers(customizers);
    }
    return builder;
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) RestTemplateCustomizer(org.springframework.boot.web.client.RestTemplateCustomizer) HttpMessageConverters(org.springframework.boot.autoconfigure.http.HttpMessageConverters) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

RestTemplateCustomizer (org.springframework.boot.web.client.RestTemplateCustomizer)2 Test (org.junit.Test)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 HttpMessageConverters (org.springframework.boot.autoconfigure.http.HttpMessageConverters)1 RestTemplateBuilder (org.springframework.boot.web.client.RestTemplateBuilder)1 Bean (org.springframework.context.annotation.Bean)1 RestTemplate (org.springframework.web.client.RestTemplate)1