์™ธ๋ถ€ ์„ค์ • ํŒŒ์ผ

์™ธ๋ถ€์—์„œ ์ฃผ์ž…ํ•ด์•ผ ํ•˜๋Š” ๊ฒƒ๋“ค์„ ์†Œ์Šค ์ฝ”๋“œ์— ์“ฐ์ง€ ์•Š๊ณ , application.properties๋‚˜ application.ymlํŒŒ์ผ์— ๋„ฃ์–ด ์‚ฌ์šฉํ•œ๋‹ค.

์ฆ‰, ์™ธ๋ถ€ ์„ค์ •๊ฐ’๋“ค์„ ๊ด€๋ฆฌํ•˜๋Š” ํŒŒ์ผ์ด๋‹ค.

1. application properties

  • resources ๋””๋ ‰ํ† ๋ฆฌ ํ•˜์œ„์— ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋œ๋‹ค.
  • key-value ํ˜•์‹์„ ์‚ฌ์šฉํ•œ๋‹ค.
  • .์„ ์ด์šฉํ•ด ๊ณ„์ธต์  ๊ตฌ์กฐ๋ฅผ ์ด๋ฃฌ๋‹ค.
spring.datasource.url=jdbc:h2:dev
spring.datasource.username=SA
spring.datasource.password=password

1-1. List

application.servers[0].ip=127.0.0.1
application.servers[0].path=/path1
application.servers[1].ip=127.0.0.2
application.servers[1].path=/path2
application.servers[2].ip=127.0.0.3
application.servers[2].path=/path3

1-2. ํ•œ ํŒŒ์ผ์—์„œ์˜ ๋‹ค์ค‘ Profile

  • โ€™#โ€”โ€˜๋กœ ๊ตฌ๋ถ„
logging.file.name=myapplication.log
bael.property=defaultValue
#---
spring.config.activate.on-profile=dev
spring.datasource.password=password
spring.datasource.url=jdbc:h2:dev
spring.datasource.username=SA
bael.property=devValue
#---
spring.config.activate.on-profile=prod
spring.datasource.password=password
spring.datasource.url=jdbc:h2:prod
spring.datasource.username=prodUser
bael.property=prodValue

1-3. ์—ฌ๋Ÿฌ ํŒŒ์ผ์˜ Profile

  • application.<>.properties์—์„œ <>์˜ ์œ„์น˜์— ๋„ค์ด๋ฐ์„ ์ ์ ˆํžˆ ํ•˜๋ฉด ๋œ๋‹ค.

2. application yml

  • .์—†์ด ๊ณ„์ธต ๊ตฌ์กฐ ํ˜•์‹์œผ๋กœ ๊ฐ’์„ ์ง€์ •ํ•œ๋‹ค.
  • ๋ฐ˜๋ณต๋˜๋Š” key ์ ‘๋‘์‚ฌ๊ฐ€ ์ œ๊ฑฐ๋˜๊ณ  ๊ตฌ์กฐ๊ฐ€ ๋ช…ํ™•ํžˆ ๋“œ๋Ÿฌ๋‚œ๋‹ค.
  • ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ๋“ค์—ฌ์“ฐ๊ธฐ๊ฐ€ ๋งค์šฐ ์ค‘์š”ํ•˜๋‹ค.
  • ๋˜ํ•œ ์ž‘์„ฑ ์ˆœ์„œ์— ๋”ฐ๋ผ ์˜ํ–ฅ์„ ๋ฐ›๋Š”๋‹ค.
spring:
    datasource:
        password: password
        url: jdbc:h2:dev
        username: SA

2-1. List

application:
    servers:
    -   ip: '127.0.0.1'
        path: '/path1'
    -   ip: '127.0.0.2'
        path: '/path2'
    -   ip: '127.0.0.3'
        path: '/path3

2-2. ์—ฌ๋Ÿฌ ํŒŒ์ผ์˜ Profile

  • โ€™โ€”โ€˜๋กœ ๊ตฌ๋ณ„
logging:
  file:
    name: myapplication.log
---
spring:
  config:
    activate:
      on-profile: staging
  datasource:
    password: 'password'
    url: jdbc:h2:staging
    username: SA
bael:
  property: stagingValue


3. ์ฃผ์˜์‚ฌํ•ญ

๋™์‹œ์— ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ application.properties๊ฐ€ ํ•ญ์ƒ ๋งˆ์ง€๋ง‰์— ๋กœ๋“œ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฎ์–ด์“ฐ๊ฒŒ ๋œ๋‹ค.

Leave a comment