package com.cpop.core.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @author DB
 * @version 1.0.0
 * @since 2023-12-08 16:35
 */
@Configuration
public class RestTemplateConfig {

    @Bean
    public RestTemplate restTemplate() {
        // 创建一个 HttpComponentsClientHttpRequestFactory 客户端请求工厂实例
        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
        // 设置连接超时时间为 5 秒
        requestFactory.setConnectTimeout(5000);
        // 设置读取超时时间为 10 秒
        requestFactory.setReadTimeout(10000);
        // 使用 HttpComponentsClientHttpRequestFactory 客户端请求工厂实例创建 RestTemplate 实例
        return new RestTemplate(requestFactory);
    }

}
