티스토리 뷰
Spring Cloud Config
- 분산 시스템에서 서버 클라이언트 구성에 필요한 설정 정보를 외부 시스템에서 관리
- 하나의 중앙화된 저장소에서 구성요소 관리 가능
- 각 서비스를 다시 빌드하지 않고, 바로 적응 가능
- 애플리케이션 배포 파이프라인을 통해 환경에 맞는 구성 정보 사용 (예: DEV, UAT, PROD)
방법
1. github에 Repository를 Private으로 생성하고 yml 파일 업로드 아래는 파일명 예제
예) chatapp-dev.yml, chatapp-prod.yml
2. github 엑세스 토큰키 생성
3. 스프링 부트 프로젝트 생성하고 build.gradle 수정(최신 스프링부트 버전 3.0.5 기준)
좀 더 안정화된 버전을 쓰고 싶다면 스프링 부트 2.5.x나 2.7.x 라인을 추천
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.5'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.greyfolk99'
version = '0.0.1'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2022.0.1")
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-config-server'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
4. application.yml 파일에다가 아래 설정 (username, password는 따로 .gitignore된 파일에다가 숨김)
- username : email 또는 도메인 제외한 username
- password : 2번에서 생성한 토큰키 (깃헙 계정 패스워드로의 인증은 deprecated됨)
server:
port: 8888
spring:
application:
name: config-service
cloud:
config:
server:
git:
uri: https://github.com/greyfolk99/spring-cloud-config.git
default-label: main
username: ${secret.github.username}
password : ${secret.github.token}
5. 서버 실행 후 테스트
- 만약 저장소에 chatapp-dev.yml로 만들었다면, http://localhost:8888/chatapp/dev 이런식
- 만약 파일명이 chatapp.yml 같이 프로파일(예: dev, prod)이 설정되어있지 않다면 http://localhost:8888/chatapp/default
결과물 예제 (http://localhost:8888/chatapp/dev) :
{
"name": "chatapp",
"profiles": [
"dev"
],
"label": null,
"version": "64b9fa39ce577856858e1eaa9596131a889d7017",
"state": null,
"propertySources": [
{
"name": "https://github.com/greyfolk99/spring-cloud-config.git/chatapp-dev.yml",
"source": {
// 해당 파일에 들어있는 프로퍼티 키와 값
"token.expiration_time": 86400000,
"token.secret": "user_token"
}
}
]
}
반응형
'Programming & CS > Spring & Spring Boot' 카테고리의 다른 글
[Spring Boot] 구글 로그인 기능 redirect_url_mismatch (1) | 2023.03.19 |
---|
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 형상 관리
- Spring cloud
- 토이 프로젝트
- MLOps
- 회원 테이블
- 멀티레포
- Polyrepo
- Microservice
- stable diffusion
- springboot
- 디스코드 봇
- monorepo
- discord bot
- Multirepo
- Hypernetwork
- Kubernetes
- vae
- 모노레포
- load balancing
- Embedding
- Textual Inversion
- spring boot
- 로드밸런서
- tauri
- 분산 처리
- load balance
- Spring Security
- spring cloud config
- 소프트웨어 방법론
- oauth2
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함