Spring Boot 2.4 profile 환경별 설정하기

1. 스프링 부트 2.4.0 이전의 profile 설정


# application.yml

# default
spring:
    profiles:
        active: local
---
spring:
    profiles: local
# 기타 설정 .. 
---
spring:
    profiles: dev
# 기타 설정 .. 
---
spring:
    profiles: prod
# 기타 설정 .. 
  • yml 파일에서 여러 profiles을 선언하고 선택하는 방식으로 사용합니다.


2. 스프링 부트 2.4.0 이후의 profile 설정


# default
spring:
  profiles:
    active: local

---
spring:
  config:
    activate:
      on-profile: local
# 기타 설정 .. 
---
spring:
  config:
    activate:
      on-profile: prod
# 기타 설정 ..       
---
spring:
  config:
    activate:
      on-profile: test 
# 기타 설정 .. 
---
spring:
  profiles:
    group:
      "dev": "test,local"
  • sring.profiles 가 deprecated 되고 spring.config.activate.on-profile 로 더 직관적으로 알아 볼 수 있도록 변경되었습니다.
  • on-profile이 설정되있는 profile에서는 spring.profiles.active, spring.profiles.include 를 사용할 수 없습니다.
  • group을 이용하여 여러 프로파일들을 한꺼번에 그룹지어 하나의 프로파일로 만들 수 있습니다.



[https://tangoblog.tistory.com/13]
[https://1minute-before6pm.tistory.com/12]


© 2021. By Backtony