Springframework 의 RestTemplate 이용 하여, http 통신 구성 시 ,
public static <T> ResponseEntity<T> send(String url, HttpMethod method, HttpHeaders header, Map<String, Object> params, Class<T> responseType) {
HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory();
httpFactory.setConnectTimeout(5*1000);
httpFactory.setReadTimeout(5*1000);
RestTemplate restTemplate = new RestTemplate(httpFactory);
HttpEntity<Object> entity = new HttpEntity<>(header);
return restTemplate.exchange(url, method, entity, responseType, params);
}
timeout 설정으로 HttpComponentsClientHttpRequestFactory 이용 시, 에러 발생!
java.lang.ClassNotFoundException: org.apache.http.impl.client.HttpClients
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na]
at org.springframework.http.client.HttpComponentsClientHttpRequestFactory.<init>(HttpComponentsClientHttpRequestFactory.java:79) ~[spring-web-5.3.25.jar:5.3.25]
[Error] Create a new instance of the HttpComponentsClientHttpRequestFactory with a default HttpClient based on system properties
HttpComponentsClientHttpRequestFactory 참조하는 HttpClient가 없다는 오류!
https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient 이동
version 선택 후, lib 등록!
implementation("org.apache.httpcomponents:httpclient:4.5")
'skill > Java.Kotlin' 카테고리의 다른 글
[Swawgger] GetMapping @RequestBody Error (0) | 2023.08.24 |
---|---|
Json Data 시, 응답에 특정 데이터 제외 처리 (0) | 2023.08.07 |
Springboot request param VO class로 받을 시, 필수 값 null일 경우 exception handler 처리 (0) | 2023.02.01 |
Springboot @RequestParam null 일 경우, exception handler 처리 (0) | 2023.01.31 |
[Kotlin] 배열 만들기 List<Int>, List<String> (0) | 2022.04.27 |