티스토리 뷰

yaml 파일을 활용하여 로컬, 개발, 배포 환경을 하나의 파일에 설정하고 관리해보자.

 

application.yml

spring:
  profiles:
    group:
      "local": common,testdb
      "dev": common,testdb
      "prod": common,proddb

---

spring:
  config:
    activate:
      on-profile: testdb
  datasource:
    url: jdbc:postgresql://test-server/TDB
    username: dongjun
    password: 1234

---

spring:
  config:
    activate:
      on-profile: proddb
  datasource:
    url: jdbc:postgresql://prod-server/PDB
    username: dongjun
    password: 1234

---

spring:
  application:
    name: api-service
  config:
    activate:
      on-profile: common

server:
  port: 8081

위와 같이 각각의 profile을 가지고 그룹을 지어 관리가 가능하다.

 

실행

IntelliJ에서 애플리케이션을 실행할때는 아래와 같이 설정해주면 된다.

  1. Edit Configurations... 
  2. Spring Boot Application 선택
  3. Active profiles에 실행할 profile 명 입력 후 실행

 

테스트 코드 실행

실행할 테스트코드 상단에 @ActiveProfiles을 추가해준다.

 

배포

java -jar /test/testApp.jar --spring.config.location=/test/application.yml --spring.profiles.active=dev
  • --spring.config.location={주입할 설정파일}
  • --spring.profiles.active={실행할 profile 명}

 

링크
최근에 올라온 글
글 보관함
«   2025/05   »
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