๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • ์žฅ์›์ต ๊ธฐ์ˆ ๋ธ”๋กœ๊ทธ
๐Ÿ’Š Java & Kotlin & Spring/- spring framework +

Spring Cloud Config์˜ name, profiles ๊ทธ๋ฆฌ๊ณ  Github ๋ฅผ ์—ฐ๋™ํ•ด์„œ ์„ค์ • ํŒŒ์ผ ๊ด€๋ฆฌํ•˜๊ธฐ

by Wonit 2021. 4. 27.

ํ•ด๋‹น ๊ธ€์€ Spring Cloud Config ๋กœ Application์˜ ์„ค์ • ์ •๋ณด๋ฅผ ์ค‘์•™์—์„œ ๊ด€๋ฆฌํ•˜๊ธฐ์— ์˜์กดํ•˜๋Š” ๊ธ€์ž…๋‹ˆ๋‹ค. ์‹ค์Šต ํ™˜๊ฒฝ์„ ๋”ฐ๋ผํ•˜์‹œ๋ ค๋ฉด ์ด์ „ ๊ธ€์— ๋‚˜์˜จ ์‹ค์Šต์„ ๋”ฐ๋ผํ•˜์‹œ๊ธธ ๊ถŒ๊ณ ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

๋ชฉ์ฐจ

  • ์™ธ๋ถ€ ์„ค์ • ๊ด€๋ฆฌ ๋ฐฉ๋ฒ•
    • ๊ธฐ๋ณธ
    • ๋งŒ์•ฝ ์„ค์ • ํŒŒ์ผ์ด ์—ฌ๋Ÿฌ ๊ฐœ๋ผ๋ฉด? ๊ฒŒ๋‹ค๊ฐ€ ๊ฐ๊ฐ ๋‹จ๊ณ„๋ณ„๋กœ ๊ตฌ์„ฑํ•ด์•ผ ํ•˜๋Š” ํŒŒ์ผ์ด ๋‹ค๋ฅด๋‹ค๋ฉด?
    • ์ด๋Ÿด ๋•Œ profiles ๊ฐ€ ๋“ฑ์žฅ
  • profiles
    • Spring boot ์—์„œ profiles ์— ๋”ฐ๋ฅธ ์„ค์ •
  • ๊ฐ๊ธฐ ๋‹ค๋ฅธ ์„ค์ • ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ
    • naming ์ „๋žต
    • config ์„œ๋ฒ„ url ์— ๋”ฐ๋ฅธ ์„ค์ • profile
  • Config ์„œ๋ฒ„์™€ Git Remote Repository ์—ฐ๋™ํ•˜์—ฌ ์„ค์ • ํŒŒ์ผ ๊ด€๋ฆฌํ•˜๊ธฐ
    • Git Repository ์ƒ์„ฑ
    • Git ์ €์žฅ์†Œ ์ƒ์„ฑ
    • Config ์„œ๋ฒ„์—์„œ git url ์—ฐ๊ฒฐ
    • User service fetch from config server
  • Config Client ์—์„œ profiles ์— ๋”ฐ๋ผ์„œ ๋‹ค๋ฅธ config ํŒŒ์ผ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

Spring Cloud Config ์„œ๋ฒ„๊ฐ€ ๊ฐ๊ธฐ ๋‹ค๋ฅธ ์„ค์ • ํŒŒ์ผ์„ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ธฐ ์ „์— ๊ธฐ๋ณธ์ ์œผ๋กœ Spring Boot ์—์„œ ์™ธ๋ถ€ ์„ค์ •์„ ์–ด๋–ป๊ฒŒ ๊ด€๋ฆฌํ•˜๊ณ  ๊ตฌ๋ถ„ํ•˜๋ฉฐ ์‚ฌ์šฉํ•˜๋Š”์ง€ ๋จผ์ € ์•„์ฃผ ๊ฐ„๋žตํ•˜๊ฒŒ ์•Œ์•„๋ณด๋„๋ก ํ•˜์ž.

 

์Šคํ”„๋ง ๋ถ€ํŠธ์˜ ์™ธ๋ถ€ ์„ค์ • ๊ด€๋ฆฌ ๋ฐฉ๋ฒ•

Spring Boot Application ์—์„œ ์™ธ๋ถ€ ์„ค์ •์— ๊ฐ’์„ ์ฃผ์ž…ํ•  ๋•Œ๋Š” ์ž˜ ์•Œ๋‹ค์‹ถ์ด application.properties๋‚˜ application.yml๋กœ ๊ตฌ์„ฑํ•˜๊ณค ํ•œ๋‹ค.

 

Spring boot application ์ด ๋นŒ๋“œ๋˜๊ณ  ์‹คํ–‰๋  ์‹œ์ ์— ๊ฐ€์žฅ ๋จผ์ € application.yml ์ด๋‚˜ application.properties ํŒŒ์ผ์„ ์ฐพ๊ณ , ํ•ด๋‹น ํŒŒ์ผ์— ๊ธฐ์ˆ ๋œ ๋‚ด์šฉ์„ ํ† ๋Œ€๋กœ ์™ธ๋ถ€ ์„ค์ •์„ ์ฃผ์ž…ํ•˜๊ฒŒ ๋œ๋‹ค.

 

๊ทธ๋Ÿผ ๋งŒ์•ฝ ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ๊ณผ Production ํ™˜๊ฒฝ์—์„œ ์“ฐ์ผ ์„ค์ •์„ ๋‹ค๋ฅด๊ฒŒ ํ•˜๊ณ ์‹ถ๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ๊นŒ?

์˜ˆ๋ฅผ ๋“ค์–ด Test ํ™˜๊ฒฝ์—์„œ๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๊ฐ€๋ณ๊ฒŒ ๋Œ์•„๊ฐ€๋Š” h2 ๋กœ ๊ตฌ์„ฑํ•˜๊ณ  ์‹ถ๊ณ  Production ํ™˜๊ฒฝ์—์„œ๋Š” ์•ˆ์ •์ ์ธ maria db๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด?

 

๋ฌผ๋ก  ๊ฐ๊ฐ ์„ค์ • ํŒŒ์ผ์— ๋“ค์–ด๊ฐˆ ์„ค์ • ์ •๋ณด๋ฅผ ํ™˜๊ฒฝ์— ๋”ฐ๋ผ์„œ ๊ฐ๊ธฐ ๋‹ค๋ฅธ ๋‚ด์šฉ์„ ์ž…๋ ฅํ•˜๋ฉด ๋˜๊ฒ ์ง€๋งŒ, ๊ทธ ๋ฐฉ๋ฒ•์€ ๋งค์šฐ ์›์‹œ์ ์ธ ๋ฐฉ๋ฒ•์ด๋ผ๊ณ  ์ƒ๊ฐํ•œ๋‹ค.

 

์ด๋Ÿฐ ์ƒํ™ฉ์—์„œ ์กฐ๊ธˆ ๋” ์šฐ์•„ํ•˜๊ฒŒ ์„ค์ • ์ •๋ณด๋ฅผ ๊ต์ฒดํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด ๋ฐ”๋กœ Spring Profiles ๋ผ๊ณ  ์ƒ๊ฐํ•œ๋‹ค.

 

Spring Profiles ๋ž€?

Spring Profiles ๋ž€ ์šฐ๋ฆฌ์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์„ค์ •์„ ํ•˜๊ณ  ํŠน์ • ํ™˜๊ฒฝ์—์„œ๋งŒ ๋Œ์•„๊ฐ€๊ฒŒ ํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค.


๋ณดํ†ต ํด๋ž˜๋“œ ๋‹จ์œผ๋กœ ๊ฐ€์„œ๋Š” @Component๋‚˜ @Configuration ์—์„œ @Profiles ์–ด๋…ธํ…Œ์ด์…˜์„ ํ†ตํ•ด ํ”„๋กœํ•„์„ ๊ตฌ๋ถ„ํ•˜๋Š”๋ฐ, ์‰ฝ๊ฒŒ ๋ง ํ•ด์„œ

 

Spring ์˜ Profiles ๋ฅผ ์ด์šฉํ•œ๋‹ค๋ฉด Application ์ด ์‹คํ–‰๋˜๋Š” ํ™˜๊ฒฝ์— ๋”ฐ๋ผ์„œ ๋‹ค๋ฅธ Bean ๋“ค์„ ๋งคํ•‘ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค.

 

ํ˜„์žฌ๋Š” Spring Cloud Config ์— ๋Œ€ํ•œ ์„ค๋ช…์ด ๊ฐ€์žฅ ํฐ ๋ชฉ์ ์ด๋‹ˆ Spring Boot ์—์„œ Profiles ๋ฅผ ์ด์šฉํ•œ ๊ฐ๊ธฐ ๋‹ค๋ฅธ ํ™˜๊ฒฝ ๊ตฌ์„ฑ์€ Profile.active ์„ ์ด์šฉํ•˜์—ฌ ๋‹ค๋ฅธ ์„ค์ • ์ •๋ณด(application.properties) ๋ถˆ๋Ÿฌ์˜ค๊ธฐ ์„ ํ™•์ธํ•ด์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

Spring Cloud Config ์—์„œ ๊ฐ๊ธฐ ๋‹ค๋ฆฐ ์„ค์ • ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ

์ด์ œ ๋‹ค์‹œ ๋ณธ๋ก ์œผ๋กœ ๋Œ์•„๊ฐ€์„œ Spring Cloud Config ์—์„œ๋Š” ์–ด๋–ป๊ฒŒ profiles ๋ฅผ ์ด์šฉํ• ๊นŒ?

 

์ •๋‹ต์€ URL์— ์žˆ๋‹ค.

 

Spring Cloud Config ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์™ธ๋ถ€ ์„ค์ • ํŒŒ์ผ์˜ 3๊ฐ€์ง€ ์ •๋ณด(name, profiles, label)๋ฅผ URL ๊ฒฝ๋กœ์— ๋”ฐ๋ผ์„œ ๊ตฌ๋ถ„์ง€์–ด๋†“์•˜๋‹ค.

 

 

๋งŒ์•ฝ application.yml ํŒŒ์ผ์ด ์„ค์ • ์ •๋ณด์— ์กด์žฌํ•œ๋‹ค๋ฉด Global ํ•˜๊ฒŒ ์ ์šฉ๋œ๋‹ค.


์ฆ‰, ์„ค์ • ์ •๋ณด๋ฅผ ๊ฐ€์ ธ๊ฐ€๋Š” ๋ชจ๋“  URL์— application.yml ์ด ์ ์šฉ๋œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

 

์˜ˆ๋ฅผ ๋“ค์–ด์„œ ๊ทธ๋Ÿผ

 

์˜ˆ๋ฅผ ๋“ค์–ด์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์„ค์ • ํŒŒ์ผ์ด ์กด์žฌํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด์ž.

 

  • application.yml
  • user-service.yml
  • user-service-test.yml
  • user-service-prod.yml
  • order-service-prod.yml

 

๊ทธ๋Ÿผ ๊ฐ๊ฐ์˜ name๊ณผ profiles ์ •๋ณด๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋‹ค.

  • application.yml
    • name: none
    • profiles: none
  • user-service.yml
    • name: user-service
    • profiles: default
  • user-service-test.yml
    • name: user-service
    • profiles: test
  • user-service-prod.yml
    • name: user-service
    • profiles: profiles
  • order-service-prod.yml
    • name: order-service
    • profiles: prod

 

๊ทธ๋Ÿผ ๊ฐ๊ฐ ์–ด๋–ค url๋กœ ํ˜ธ์ถœ์„ ํ•ด์•ผ์ง€ ์›ํ•˜๋Š” ํŒŒ์ผ์ด ๋‚˜์˜ฌ๊นŒ?

 

์‚ฌ์‹ค์ƒ ์œ„์˜ ํŒŒ์ผ์€ Config ์„œ๋ฒ„์—์„œ name์ด user์ด ๋  ์ˆ˜๋„ ์žˆ๊ณ  user-service๊ฐ€ ๋  ์ˆ˜ ๋„ ์žˆ์œผ๋ฉฐ user-service-test ๋„ ๋  ์ˆ˜ ์žˆ๋‹ค. ์ด๋Š” ์ •ํ•˜๋Š” ์šฐ๋ฆฌ์˜ ์—ญ๋Ÿ‰์ด๋‹ˆ ์šฐ๋ฆฌ๋Š” user-serive ๊ฐ€ ํ•˜๋‚˜์˜ name์ด๋ผ๊ณ  ๊ฐ€์ •ํ•˜์ž

์ด๋ฅผ ๊ตฌ๋ถ„ํ•˜๋Š” ํŒ์€ name ์ด ๋™์ผํ•œ profiles๋Š” ๋ชจ๋‘ ๊ธฐ๋ณธ์ ์œผ๋กœ name.yml ํŒŒ์ผ์„ ๊ฐ–๋Š”๊ฒƒ์ด๋‹ค.

 

์ฆ‰, ์œ„์™€ ๊ฐ™์€ ์ƒํ™ฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ˜•ํƒœ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.

 

Config ์„œ๋ฒ„์™€ Git Remote Repository ์—ฐ๋™ํ•˜์—ฌ ์„ค์ • ํŒŒ์ผ ๊ด€๋ฆฌํ•˜๊ธฐ

๊ฐ€๋ณ๊ฒŒ Config ์„œ๋ฒ„์˜ name๊ณผ profiles ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์•˜์œผ๋‹ˆ ์ด์ œ ์ง์ ‘ ์‹ค์Šตํ•ด๋ณด๋„๋ก ํ•˜์ž.

 

์ง€๋‚œ ์‹œ๊ฐ„์— ์šฐ๋ฆฌ๋Š” Config ์„œ๋ฒ„๋ฅผ ๊ตฌ์„ฑํ•˜์˜€๊ณ  Native File System์— ์กด์žฌํ•˜๋Š” Local File ๋“ค์„ Config ์„œ๋ฒ„๊ฐ€ ๋กœ๋“œํ•˜์—ฌ ๊ฐ๊ธฐ ์„œ๋ฒ„๋กœ ๋ฟŒ๋ ค์ฃผ๋Š” ๊ฒƒ์„ ๊ตฌํ˜„ํ•˜์˜€๋‹ค.

 

Config Server์˜ ๊ธฐ๋ณธ๊ณผ ์„ค์ • ๋ฐฉ๋ฒ•์„ ์•„์‹ ๋‹ค๋ฉด ๋ฌด๋ฐฉํ•˜์ง€๋งŒ ๋งŒ์•ฝ ์ฒ˜์Œ์ด์‹œ๊ณ  ์ •ํ™•ํ•˜๊ฒŒ ์‹ค์Šต์„ ๋”ฐ๋ผํ•˜์‹œ๊ณ  ์‹ถ๋‹ค๋ฉด Spring Cloud Config ๋กœ Application์˜ ์„ค์ • ์ •๋ณด๋ฅผ ์ค‘์•™์—์„œ ๊ด€๋ฆฌํ•˜๊ธฐ ์„ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”

 

๊ฑฐ์˜ ๋Œ€๋ถ€๋ถ„์˜ MSA ํ”„๋กœ์ ํŠธ์—์„œ Local ํ™˜๊ฒฝ์— Config ํŒŒ์ผ์„ ๊ด€๋ฆฌํ•˜๋Š” ๊ณณ์€ ์—†์„ ๊ฒƒ ๊ฐ™๋‹ค.

 

๋Œ€๋ถ€๋ถ„ Git์„ ์ด์šฉํ•ด์„œ ๊ด€๋ฆฌํ•˜๋„๋ก ํ•˜๋Š”๋ฐ, ์šฐ๋ฆฌ๋„ Native File System ์—์„œ Git ์œผ๋กœ ์„ค์ • ์ •๋ณด ์ €์žฅ์†Œ๋ฅผ ์˜ฎ๊ฒจ๋ณด์ž.

์ˆœ์„œ

  1. Git Remote Repository ์ƒ์„ฑ & Local Git ์ €์žฅ์†Œ ์ƒ์„ฑ
  2. ์„ค์ • ํŒŒ์ผ ์ถ”๊ฐ€
  3. Config Server ์—์„œ Git URL ์—ฐ๊ฒฐ
  4. User-Service ์—์„œ Config Server ๋กœ ๋ถ€ํ„ฐ ๋ฐ›์€ ์„ค์ • ํŒŒ์ผ ์ด์šฉํ•˜๊ธฐ

Git Remote Repository ์ƒ์„ฑ & Local Git ์ €์žฅ์†Œ ์ƒ์„ฑ

 

์šฐ์„  github ์— ๋“ค์–ด๊ฐ€์„œ ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•˜๋„๋ก ํ•˜์ž.

 

์ด๋ฆ„์€ ๊ฐ„๋‹จํ•˜๊ฒŒ msa-configurations ๋ผ๊ณ  ์ง€์ •ํ•˜๊ฒ ๋‹ค.

 

 

๊ทธ๋ฆฌ๊ณ  ๋กœ์ปฌ ํŒŒ์ผ์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์–ด๋กœ git Local ์ €์žฅ์†Œ๋ฅผ ์ƒ์„ฑํ•˜์ž

 

mkdir git-msa-config

cd git-msa-config

git init

git remote add origin https://github.com/์ €์žฅ์†Œ ์ด๋ฆ„.git

์„ค์ • ํŒŒ์ผ ์ถ”๊ฐ€

๊ทธ๋ฆฌ๊ณ  ๊ฐ๊ธฐ ๋‹ค๋ฅธ ์„ค์ • ํŒŒ์ผ๋“ค์„ ์ €์žฅํ•˜์ž.

 

  • application.yml
  • user-service.yml
  • user-service-test.yml
# application.yml
default:
  owner: config-service's git folder
  content: :) ์•ˆ๋…•ํ•˜์„ธ์š” ๊ฐ๊ฐ์˜ ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค์—์„œ ์‚ฌ์šฉ๋  ๋ฐ์ดํ„ฐ์ž…๋‹ˆ๋‹ค. :)

# user-service.yml
spring:
  datasource:
    driver: com.h2.Driver
    url: dbUrl
    username: admin
    password: admin

token:
  key: my_token_secret_key

default:
  message: user-service ์—์„œ global profiles ์—์„œ ์‚ฌ์šฉํ•  ์„ค์ • ์ •๋ณด๋“ค

# user-service-test.yml

spring:
  datasource:
    driver: com.mysql.jdbc.Driver
    url: dbUrl
    username: test
    password: test

default:
  message: test profiles ์—์„œ ์‚ฌ์šฉํ•  ์„ค์ • ์ •๋ณด๋“ค

 

๊ทธ๋ฆฌ๊ณ  ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ์ƒˆ๋กœ ์ƒ์„ฑ๋œ ํŒŒ์ผ๋“ค์„ push ํ•ด๋ณด์ž.

 

git add -A
git commit -m"initial commit"
git push origin master

 

๊ทธ๋Ÿผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž˜ ์ €์žฅ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

Config Server ์—์„œ Git URL ์—ฐ๊ฒฐ

์ด์ œ Config Server ์—์„œ ์šฐ๋ฆฌ์˜ ์„ค์ • ์ •๋ณด๋“ค์ด ์ €์žฅ๋œ ์ €์žฅ์†Œ์™€ ์—ฐ๊ฒฐ์„ ํ•ด๋ณด์ž.

 

Config Server ์— ์žˆ๋Š” application.yml ์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•ด๋ณด์ž.

 

๋งŒ์•ฝ ์ง€๋‚œ ์‹œ๊ฐ„์— ์‹ค์Šต์„ ๋”ฐ๋ผํ•œ๋‹ค๋ฉด native active profiles ์ด ์กด์žฌํ• ํ…๋ฐ, ํ•ด๋‹น ํ”„๋กœํŒŒ์ผ์„ ์ง€์›Œ์•ผ ํ•œ๋‹ค.

 

server:
  port: 8888

spring:
  application:
    name: config-service

  cloud:
    config:
      server:
        git:
          uri: https://github.com/dhslrl321/mas-configurations

 

๊ทธ๋ฆฌ๊ณ  api tester ๋‚˜ ๋ธŒ๋ผ์šฐ์ €๋กœ http://localhost:8888/user-service/test ๋กœ ์ ‘๊ทผํ•œ๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ฌ ๊ฒƒ์ด๋‹ค.

 

token.key๋Š” ์ถ”ํ›„์— ์ถ”๊ฐ€ํ•œ ๋ฐ์ดํ„ฐ๋ผ ์œ„์˜ ๋ฐ์ดํ„ฐ์—๋Š” token.key ์ •๋ณด๊ฐ€ ์—†๋Š”์  ์–‘ํ•ด๋ฐ”๋ž๋‹ˆ๋‹ค.

์‚ฌ์‹ค ๋ฏผ๊ฐ ์ •๋ณด๋Š” git private repository๋กœ ์ง€์ •ํ•˜๋Š”๊ฒŒ ๋งž๋‹ค. ๋” ๋‚˜์•„๊ฐ€์„œ๋Š” ์•”ํ˜ธํ™”๋ฅผ ํ•ด์•ผํ•˜๋Š”๋ฐ, ์ด๋Š” ๋‹ค์Œ ์‹œ๊ฐ„์— ์•Œ์•„๋ณด๋„๋ก ํ•˜์ž

 

๊ทธ๋Ÿด ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™์ด git ๊ณ„์ • ์ •๋ณด๋ฅผ ๋“ฑ๋กํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

 

server:
  port: 8888

spring:
  application:
    name: config-service

  cloud:
    config:
      server:
        git:
          uri: https://github.com/dhslrl321/mas-configurations
          username: uname123
          password: pwd1234

Config Client ์—์„œ profiles ์— ๋”ฐ๋ผ์„œ ๋‹ค๋ฅธ config ํŒŒ์ผ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

 

์ด์ œ Config Client ์ธก, ์ฆ‰ User-Service ์—์„œ ์•„๋ž˜์™€ ๊ฐ™์ด controller ๋ฅผ ๊ตฌ์„ฑํ•ด์„œ ์–ด๋–ค ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๋Š”์ง€ ์ถœ๋ ฅํ•ด๋ณด์ž.

 

@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class UserServiceApplication {

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

    @GetMapping("/config/database")
    public String database(@Value("${spring.datasource.driver}") String driver,
                           @Value("${spring.datasource.url}") String url,
                           @Value("${spring.datasource.username}") String username,
                           @Value("${spring.datasource.password}") String password,
                           @Value("${token.key}") String tokenKey) {
        return "driver: " + driver + "\n"
                + "url: " + url + "\n"
                + "username: " + username + "\n"
                + "password: " + password + "\n\n"
                + "token key: " + tokenKey;
    }
}

 

 

 

๊ทธ๋Ÿผ user-service์— ์žˆ๋Š” token ์ •๋ณด์™€ user-service-test ์— ์žˆ๋Š” datasource ์ •๋ณด๋ฅผ ์ž˜ ๋ฐ›์•„์˜ค๋Š” ๊ฒƒ์œผ๋กœ ํ™•์ธ๋œ๋‹ค.

 

๋Œ“๊ธ€