refactor: RestTemplateConfig 통일
parent
ad07645bb6
commit
d0cb4eefbd
@ -1,4 +1,4 @@
|
||||
package egovframework.config;
|
||||
package go.kr.project.api.config;
|
||||
|
||||
import com.google.common.util.concurrent.RateLimiter;
|
||||
import egovframework.configProperties.RestTemplateProperties;
|
||||
@ -1,39 +0,0 @@
|
||||
package go.kr.project.api.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 전역 상수 및 설정값을 관리하는 클래스
|
||||
*
|
||||
* <p>이 클래스는 애플리케이션 전반에서 사용되는 전역 설정값을 제공합니다.
|
||||
* Spring의 @Value를 통해 application.yml의 설정값을 주입받아 사용합니다.</p>
|
||||
*/
|
||||
@Component
|
||||
public class Globals {
|
||||
|
||||
/**
|
||||
* 데이터베이스 타입 (예: mariadb, oracle, mysql 등)
|
||||
*
|
||||
* <p>MyBatis Mapper XML 파일 선택 시 사용됩니다.
|
||||
* mapper-locations: classpath:mybatis/mapper/**\/*_${Globals.DbType}.xml</p>
|
||||
*
|
||||
* <p>예시:
|
||||
* <ul>
|
||||
* <li>DbType = "mariadb" → user_mariadb.xml 매핑</li>
|
||||
* <li>DbType = "oracle" → user_oracle.xml 매핑</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*/
|
||||
public static String DbType;
|
||||
|
||||
/**
|
||||
* application.yml에서 Globals.DbType 값을 주입합니다.
|
||||
*
|
||||
* @param dbType 데이터베이스 타입 (기본값: mariadb)
|
||||
*/
|
||||
@Value("${Globals.DbType:mariadb}")
|
||||
public void setDbType(String dbType) {
|
||||
Globals.DbType = dbType;
|
||||
}
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
package go.kr.project.api.config;
|
||||
|
||||
import go.kr.project.api.config.properties.VmisProperties;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* HttpClient 설정
|
||||
* Apache HttpClient 4를 사용한 RestTemplate 구성
|
||||
* VMIS 정부 API 전용 RestTemplate (vmisRestTemplate)
|
||||
*/
|
||||
@Configuration
|
||||
public class HttpClientConfig {
|
||||
|
||||
@Bean(name = "vmisRestTemplate")
|
||||
public RestTemplate vmisRestTemplate(VmisProperties props, RestTemplateBuilder builder) {
|
||||
VmisProperties.GovProps gov = props.getGov();
|
||||
int connectTimeout = gov.getConnectTimeoutMillis();
|
||||
int readTimeout = gov.getReadTimeoutMillis();
|
||||
|
||||
// HttpClient 4 방식의 RequestConfig
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setConnectTimeout(connectTimeout)
|
||||
.setSocketTimeout(readTimeout)
|
||||
.setConnectionRequestTimeout(connectTimeout)
|
||||
.build();
|
||||
|
||||
// 커넥션 풀 설정
|
||||
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
||||
cm.setMaxTotal(100);
|
||||
cm.setDefaultMaxPerRoute(20);
|
||||
|
||||
// HttpClient 생성
|
||||
CloseableHttpClient httpClient = HttpClientBuilder.create()
|
||||
.setDefaultRequestConfig(requestConfig)
|
||||
.setConnectionManager(cm)
|
||||
.build();
|
||||
|
||||
// RestTemplate에 HttpClient 적용
|
||||
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
|
||||
return builder
|
||||
.requestFactory(() -> requestFactory)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue