멀티 레포 프로젝트라면 공통된 설정 파일이 여러 군데 분포되어, 관리가 어려워 질 수 밖에 없다.
설정 관리에 곤란함을 겪어 본 적이 있어 이를 개선하기 위해 Spring Cloud Config를 사용해 보았다.
참고 공식 문서 : https://docs.spring.io/spring-cloud-config/docs/current/reference/html/
Spring Cloud Config
Spring Cloud Config provides server-side and client-side support for externalized configuration in a distributed system. With the Config Server, you have a central place to manage external properties for applications across all environments. The concepts o
docs.spring.io
설정 파일을 포함하여 제공하는 프로젝트는 "Server"라고 칭하고, 해당 설정을 가져다 쓸 어플리케이션 프로젝트는 "Client"라고 칭한다.
Server
먼저 Server 설정 파일(yml)을 private repo에 푸시하고, private repo uri, git 유저 아이디, 토큰 등을 기억 해 두자.
build.gradle 의존성 추가
dependencies {
implementation 'org.springframework.cloud:spring-cloud-config-server'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
}
application.yml
spring:
cloud:
config:
server:
git:
uri: https://github.com/???/.git // private repo git 주소
username: TEST // 유저 이름
password: TESTTOKEN // 토큰
Client
build.gradle 의존성 추가
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-config'
}
application.yml 추가 (예시는 auth 모듈)
spring:
application:
name: auth
config:
import: "optional:configserver:"
activate:
on-profile: dev
cloud:
config:
label: dev
Client는 Server 내의 많은 yml 설정 파일 중 [spring.application.name]-[spring.cloud.config.label].yml (예시에서는 auth-dev) 을 임포트 받아 구동하는 것을 확인하였다.
'Spring' 카테고리의 다른 글
Spring Cloud Gateway 연동 (0) | 2025.01.11 |
---|---|
멀티모듈매핑, 결합도 낮추기 (0) | 2025.01.06 |
Spring - Exception (0) | 2022.10.09 |
MVC2 - Filter, Interceptor (1) | 2022.10.05 |
MVC2 - 로그인(쿠키, 세션) (1) | 2022.10.03 |