∞. 트러블 슈팅 + TIL

04. Spring Boot 2.4 Profile 적용 안되던 문제

THE HEYDAZE 2021. 9. 8. 20:57
문제

더 이상 사용되지 않는 구성 속성 'spring.profiles'

 

원인

Spring Boot 2.4 버전 부터 application profile 을 작성하는 방식이 달라졌습니다 (아래 참고)

http://honeymon.io/tech/2021/01/16/spring-boot-config-data-migration.html

 

[spring-boot] 2.4 부터 변경된 구성파일 처리방식 살펴보기 - I'm honeymon(JiHeon Kim).

스프링 부트 2.4(https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.4-Release-Notes) 출시노트를 살펴보면 인상적인 2가지가 있다. 애플케이션 구성파일(application.yml 혹은 application.properties)의 작동방식

honeymon.io

 

https://stackoverflow.com/questions/64907675/including-profiles-in-spring-boot-2-4-0-version

 

Including profiles in spring boot 2.4.0 version

As a developer, I use the default dev profile in my local development environment. Here is part of my application-dev.properties file: # Profiles spring.profiles.include=auth Previously I used

stackoverflow.com

 

 

해결
이전 방식
# application.yml
spring:
  profiles:
    include: app, h2, oauth2
		# 결과적으로는 app , h2, oauth2-naver, oauth2-kakao, oauth2-google 이 설정된다
# application-h2.yml
spring:
  datasource:
    url: jdbc:h2:mem:testdb
    username: sa
    password:

  jpa:
    show-sql: true
    hibernate:
      ddl-auto: create
    properties:
      hibernate:
        format_sql: true
  h2:
    console:
      enabled: true
# application-app.yml
app:
	test: 'appConfig'
# application-oauth2.yml
spring:
  profiles:
    include: naver, kakao, google

---
spring:
  profiles: naver
  security:
    oauth2:
      client:
        registration:
          naver:
		        # client id, client-secret, redirect-uri, scope, client-name
        provider:
          naver:
            # authorization_uri, token_uri, user-info-uri, user_name_attribute
     
---
spring:
  profiles: kakao
  security:
    oauth2:
      client:
        registration:
          naver:
		        # client id, client-secret, redirect-uri, scope, client-name
        provider:
          naver:
            # authorization_uri, token_uri, user-info-uri, user_name_attribute
---
spring:
  profiles: google
  security:
    oauth2:
      client:
        registration:
          naver:
		        # client id, client-secret, redirect-uri, scope, client-name
        provider:
          naver:
            # authorization_uri, token_uri, user-info-uri, user_name_attribute
---
spring:
  profiles: facebook
  security:
    oauth2:
      client:
        registration:
          naver:
		        # client id, client-secret, redirect-uri, scope, client-name
        provider:
          naver:
            # authorization_uri, token_uri, user-info-uri, user_name_attribute
---
spring:
  profiles: github
  security:
    oauth2:
      client:
        registration:
          naver:
		        # client id, client-secret, redirect-uri, scope, client-name
        provider:
          naver:
            # authorization_uri, token_uri, user-info-uri, user_name_attribute

 

변경된 방식
# application.yml
spring:
  profiles:
    group:
      local:
        - h2
        - app
        - oauth2
      prod:
        - h2
        - app
    active: local

# 결과적으로 local( h2, app, oauth2-naver, oauth2-kakao, oauth2-google) 로 설정 된다
# application-app.yml
app:
	test: 'appConfig'
# application-h2.yml
spring:
  datasource:
    url: jdbc:h2:mem:testdb
    username: sa
    password:

  jpa:
    show-sql: true
    hibernate:
      ddl-auto: create
    properties:
      hibernate:
        format_sql: true
  h2:
    console:
      enabled: true
# application-oauth2.yml
spring:
  config:
    import:
      - classpath:/oauth2/application-naver.yml
      - classpath:/oauth2/application-kakao.yml
      - classpath:/oauth2/application-google.yml
  profiles:
    group:
      - naver
      - kakao
      - google
# /oauth2/application-naver.yml
spring:
  profiles: naver
  security:
    oauth2:
      client:
        registration:
          naver:
		        # client id, client-secret, redirect-uri, scope, client-name
        provider:
          naver:
            # authorization_uri, token_uri, user-info-uri, user_name_attribute
# /oauth2/application-kakao.yml
spring:
  profiles: kakao
  security:
    oauth2:
      client:
        registration:
          naver:
		        # client id, client-secret, redirect-uri, scope, client-name
        provider:
          naver:
            # authorization_uri, token_uri, user-info-uri, user_name_attribute
# /oauth2/application-google.yml
spring:
  profiles: google
  security:
    oauth2:
      client:
        registration:
          naver:
		        # client id, client-secret, redirect-uri, scope, client-name
        provider:
          naver:
            # authorization_uri, token_uri, user-info-uri, user_name_attribute