Spring Boot에서 HTTP 통신을 하기위한 설정은 다음과 같다.
@Configuration
public class HttpConnectionConfig {
@Value("${restTemplate.factory.readTimeout}")
private int READ_TIME_OUT;
@Value("${restTemplate.factory.connectTimeout}")
private int CONNECT_TIME_OUT;
@Value("${restTemplate.httpClient.maxConnTotal}")
private int MAX_CONNECT_TOTAL;
@Value("${restTemplate.httpClient.maxConnPerRoute}")
private int MAX_CONNECT_PER_ROUTE;
@Bean
public RestTemplate customRestTemplate(){
HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
httpRequestFactory.setConnectTimeout(CONNECT_TIME_OUT);
httpRequestFactory.setReadTimeout(READ_TIME_OUT);
HttpClient httpClient = HttpClientBuilder.create()
.setMaxConnTotal(MAX_CONNECT_TOTAL)
.setMaxConnPerRoute(MAX_CONNECT_PER_ROUTE)
.build();
httpRequestFactory.setHttpClient(httpClient);
return new RestTemplate(httpRequestFactory);
}
}
각 변수들은 application.properties에서 작성하였다.