Spring Config [3] profile과 git

최준호·2022년 3월 8일
0

Microservice Architecture

목록 보기
21/32
post-thumbnail

설정 파일은 개발 환경(local, dev, test, prod 등)에 따라 설정값을 나누고 실행할 수 있다. Spring Config에서도 동일한 기능을 지원하는데 확인해보자.

🔨file 생성

token:
  expiration_time: 86400000
  secret: user_token_dev
token:
  expiration_time: 86400000
  secret: user_token_prod

dev와 prod 두개의 파일을 각각 ecommerce-dev ecommerce-prod로 생성한다.

gateway

spring:
  cloud:
    config:
      uri: http://127.0.0.1:8888
      name: ecommerce
  profiles:
    active: prod

user-serivce

spring:
  cloud:
    config:
      uri: http://127.0.0.1:8888
      name: ecommerce
  profiles:
    active: dev

두개의 bootstrap 설정을 다음과 같이 변경하고 로그인에서 token 정보를 불러오는 곳에 브레이크 포인트를 걸어두자.

다음과 같이 user-service에서 token이 dev 설정으로 불러와지는 것을 확인할 수 있다.

gateway도 확인하면 gateway는 dev가 아닌 prod인것을 확인할 수 있다.

git repo에도 연결하여 사용할 수 있는데

server:
  port: 8888

spring:
  application:
    name: config-service
  cloud:
    config:
      server:
        git:
          uri: [git uri]
          username: [git id]
          password: [git password]

public repository의 경우 username과 password 정보는 필요 없다.

profile
코딩을 깔끔하게 하고 싶어하는 초보 개발자 (편하게 글을 쓰기위해 반말체를 사용하고 있습니다! 양해 부탁드려요!) 현재 KakaoVX 근무중입니다!

0개의 댓글