Skip to content

Instantly share code, notes, and snippets.

@gksxodnd007
Last active August 24, 2018 03:06
Show Gist options
  • Save gksxodnd007/818003f9110a637f50c9e90a32f0b945 to your computer and use it in GitHub Desktop.
Save gksxodnd007/818003f9110a637f50c9e90a32f0b945 to your computer and use it in GitHub Desktop.
spring boot profile 설정

Spring Boot Profile 설정

  • Spring Boot를 사용하기 전에는 maven을 이용했다면 <profile> 태그를 이용하여 profile을 설정하였다.
  • Spring Boot를 이용하면 보다 손쉽게 profile을 설정할 수 있다.

참고 docs : https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-profile-specific-properties

application.properties를 파일을 이용할 경우

  • application-{profile}.properties 형식으로 다음과 여러개의 파일을 생성하면 된다.
application-default.properties
application-dev.properties
application-prod.properties
  • 다음은 문서에 명시된 profile이 지정되지 않았을 때의 action이다.

if no profiles are explicitly activated, then properties from application-default.properties are loaded.

yaml파일을 이용할 경우

  • 한 파일에 profile설정이 가능하다.
  • 다음은 profile 설정 예시이다.
spring:
  profiles:
    active: default
logging:
  level:
    root: debug

---

spring:
  profiles: dev
logging:
  level:
    root: info

---

spring:
  profiles: test
logging:
  level:
    root: debug
  level.org.hibernate:
    SQL: debug
    type.descriptor.sql.BasicBinder: trace
  • ---로 구분한다. 다음은 실행 예이다.
java -jar -Dspring.profiles.active=default  ./kk-0.0.1-SNAPSHOT.jar
  • profiles를 설정해주지 않으면 기본 default로 동작한다.
java -jar -Dspring.profiles.active=dev  ./kk-0.0.1-SNAPSHOT.jar

여기서 주의할 점은 spring.profiles.active를 여러개 지정하게되면 profile 설정이 제대로 동작하지 않는다. 기본동작은 default로 동작하기에 active 설정에는 default로만 주었다. 이에 관해서는 더 알아 봐야할 것같다. 위에 이미지는 profile을 지정하여 애플리케이션을 실행시켰을때의 화면이다. profile 설정대로 로그 출력 레벨이 바뀐 것을 확인 할 수 있다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment