001package io.freefair.spring.okhttp.autoconfigure;
002
003import io.freefair.spring.okhttp.client.OkHttpClientRequestFactory;
004import okhttp3.OkHttpClient;
005import org.springframework.boot.autoconfigure.AutoConfiguration;
006import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
007import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
008import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
009import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
010import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder;
011import org.springframework.context.annotation.Bean;
012
013/**
014 * @author Lars Grefer
015 * @see RestTemplateAutoConfiguration
016 */
017@AutoConfiguration(before = RestTemplateAutoConfiguration.class, after = HttpMessageConvertersAutoConfiguration.class)
018@ConditionalOnClass({ClientHttpRequestFactoryBuilder.class, OkHttpClientRequestFactory.class})
019public class OkHttpClientRequestFactoryBuilderAutoConfiguration {
020
021    @Bean
022    @ConditionalOnMissingBean(ClientHttpRequestFactoryBuilder.class)
023    public OkHttpClientRequestFactoryBuilder okHttpClientRequestFactoryBuilder(OkHttpClient okHttpClient) {
024        return new OkHttpClientRequestFactoryBuilder(okHttpClient);
025    }
026
027}