package com.mvc.config;

import com.mvc.service.aiiden.ThrowErrorHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {
    /**
     * 创建RestTemplate对象，将RestTemplate对象的生命周期的管理交给Spring
     */
//    @Bean
//    public RestTemplate restTemplate(){
//        return new RestTemplate();
//    }

    @Bean
    public RestTemplate restTemplate() {
        SimpleClientHttpRequestFactory clientFactory  = new SimpleClientHttpRequestFactory();
        clientFactory.setConnectTimeout(3000);
        clientFactory.setReadTimeout(5000);
        RestTemplate restTemplate=new RestTemplate(clientFactory);
        restTemplate.setErrorHandler(new ThrowErrorHandler());
        return restTemplate;
    }
}
