cleanUrl: /posts/multiple-profiles-inside-a-single-yaml-file

yaml 파일에 여러개 profile 을 하나의 파일로 다룰 수 있다는 것을 알게 되서 이번에 적용하게 되었다. properties 로 할 때에는 profile 별로 따로 파일을 만들었는데 이게 매번 들어가서 수정하자니 귀찮았는데 하나의 파일로 다룰 수 있다면 상당히 편리하겠다는 생각이 들었다.

multiple profiles

multiple profiles

기존에 사용했던 profile 들은 이렇게 나누었다.

이런 파일을 하나로 다룰 수 있다면 매우 편리하겠다는 생각이 들어 이렇게 수정한다.

spring:
  jpa:
    database: mysql
    show-sql: false
    datasource:
      username: siteinfo
      password: 미정
      url: 미정

---
spring:
  profiles:
    active: qa
  jpa:
    database: mysql
    show-sql: true
    datasource:
      username: mns
      password: 비밀번호임
      url: jdbc:mysql://비밀이야:3306/directlink?useUnicode=true&characterEncoding=utf8

---
spring:
  profiles:
    active: "local"
  jpa:
    database: mysql
    show-sql: true
  datasource:
    username: mns
    password: dltmxmdlsxjspt
    url: jdbc:mysql://localhost:3306/directlink?useUnicode=true&characterEncoding=utf8

이렇게 나누는데 필요한 핵심은 spring.profiles.active 이다.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/be7233bd-be88-478a-8fd1-d9026fd8ac90/Untitled.png

intelliJ 에서 개발할 때 active profiles 에 해당하는 profile 을 입력하면 된다.