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.web.client.RestClientAutoConfiguration;
008import org.springframework.boot.web.client.RestClientCustomizer;
009import org.springframework.context.annotation.Bean;
010import org.springframework.context.annotation.Conditional;
011import org.springframework.web.client.RestClient;
012
013/**
014 * @author Lars Grefer
015 * @see RestClientAutoConfiguration
016 */
017@AutoConfiguration
018@ConditionalOnClass({RestClientCustomizer.class, RestClient.class, OkHttpClientRequestFactory.class})
019@Conditional(NotReactiveWebApplicationCondition.class)
020public class OkHttpRestClientAutoConfiguration {
021
022    @Bean
023    public RestClientCustomizer okHttpRestClientCustomizer(OkHttpClient okHttpClient) {
024        return restClientBuilder -> restClientBuilder.requestFactory(new OkHttpClientRequestFactory(okHttpClient));
025    }
026
027}