Today
-
Yesterday
-
Total
-
  • Spring Boot: profile 환경 나누기
    Spring Boot 🍃 2023. 12. 9. 00:01

    보고 배운 인강

    정리 잘 되어있는 블로그


    어플리케이션 설정을 local , develop , production 환경 등으로 구분할 때 사용한다.


    application.yml 또는 application.properties 파일에서 내용을 작성해주면 된다.


    이번 글에서는 profile을 common , local , prod 의 3가지로 구분하여 작성하고자 한다.

    • common : 모든 환경에서 공통으로 적용
    • local : 테스트 환경에서 적용
    • prod : 운영 환경에서 적용

    실습에 사용한 파일 : application.yml

    yml 파일에서 --- 문자열을 사용하면 문자열 위에 작성된 내용과 아래에 작성된 내용이 별도의 파일에서 작성된 것 처럼 해석된다.


    # 실행 할 환경 정보 작성
    
    spring:
      profiles:
        active: local
        group:
          local:
            - common
          prod:
            - common
    
    ---
    
    # profile 설정 1 : common
    
    spring:
      config:
        activate:
          on-profile: common
    
    ---
    
    # profile 설정 2 : local
    
    spring:
      config:
        activate:
          on-profile: local
    
    ---
    
    # profile 설정 3 : prod
    
    spring:
      config:
        activate:
          on-profile: prod
    

    위와 같이 작성을 한 후에,

    어플리케이션을 실행하면

    로그에서

    common profile 과 local profile 이 활성화 되었음을 알 수 있는 내용을 찾아볼 수 있다.

    'Spring Boot 🍃' 카테고리의 다른 글

    Spring Boot: Retry  (0) 2023.12.09
    Spring Boot: TestContainers 🍃🐳🧑‍🔧  (0) 2023.12.09
    rest-projection  (0) 2023.12.09
    csrf  (0) 2023.12.09
    Fixture  (0) 2023.12.09

Designed by Tistory / Custom by 얼거스