[MSA] Config Service

jineey·2024년 11월 21일

MSA

목록 보기
20/36

Config Service

📌 개요

  • 분산 시스템에서 서버 클라이언트 구성에 필요한 설정 정보(application.yml)를 외부 시스템에서 관리
  • 하나의 중앙화 된 저장소에서 구성요소 관리 가능
  • 각 서비스를 다시 빌드하지 않고, 바로 적용 가능
  • 애플리케이션 배포 파이프라인을 통해 DEV-UAT-PROD 환경에 맞는 구성 정보 사용

📌 소스코드

  1. Local Git Repository 생성
  • 디렉터리 생성
cd 파일위치
# ecommerce.yml 파일 생성
git init
git add ecommerce.yml 
git commit -m "update an application yaml file"

  • 내용 작성
# ecommerce.yml 파일 작성
token:
    expiration_time: 86400000 
    secret: make_my_secret_user_token

gateway:
    ip: 192.168.0.100
  1. Config-service 생성
  • 프로젝트 생성
    Spring Cloud Config Server 의존성 추가

  • ConfigServiceApplication.java

package com.example.configservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@SpringBootApplication
@EnableConfigServer //추가
public class ConfigServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServiceApplication.class, args);
    }

}
  • application.yml
spring:
  application:
    name: config-service
  cloud:
    config:
      server:
        git:
          uri: file://ecommerce.yml 파일 경로
		          #file://C:\Users\admin\msa (예시)

server:
  port: 8888

📌 실행결과

profile
새싹 개발자

0개의 댓글