Spring Cloud Config

2024. 10. 30. 21:47·Spring

멀티 레포 프로젝트라면 공통된 설정 파일이 여러 군데 분포되어, 관리가 어려워 질 수 밖에 없다.

설정 관리에 곤란함을 겪어 본 적이 있어 이를 개선하기 위해 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
'Spring' 카테고리의 다른 글
  • Spring Cloud Gateway 연동
  • 멀티모듈매핑, 결합도 낮추기
  • Spring - Exception
  • MVC2 - Filter, Interceptor
코드파고
코드파고
  • 코드파고
    Digging Code
    코드파고
  • 전체
    오늘
    어제
    • 분류 전체보기 (99)
      • Memorization (12)
      • Spring (18)
      • Java (1)
      • Algorithm (40)
      • Server (2)
      • DB (0)
      • CS (0)
      • CI & CD (4)
      • Architecture (0)
      • Design Patterns (0)
      • Study (1)
      • Book (9)
        • DEV (7)
        • Non-DEV (0)
      • Infra (1)
        • Kafka (6)
        • AWS (4)
      • TroubleShooting (1)
        • Etc (1)
      • Tools (0)
  • 블로그 메뉴

    • 홈
    • Github
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    architecture
    알고리즘
    Clean Code
    헥사고날아키텍쳐
    클린아키텍쳐
    Spring독학
    Spring Boot
    Spring
    SpringFramework
    clean architecture
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.2
코드파고
Spring Cloud Config
상단으로

티스토리툴바