본문 바로가기

프로그래밍

IntelliJ + Spring Boot Profile 적용하기

반응형

실행 환경에 따라 런타임에 다른 값을 적용하고자 할 때, 각기 다른 프로파일을 불러와 값을 적용할 수 있다. IntelliJ Ultimate 버전에선 다이얼로그 창에 옵션을 넣어주는 것으로 간단하게 적용할 수 있지만, Community 버전에선 그런 기능이 제공되지 않는다. 구글 검색으로 나오는 방법은 Gradle > bootRun 실행/디버그 구성 편집에서 VM 옵션에

-Dspring.profiles.active=local

를 추가하는 것이다. 하지만 이 옵션을 넣어도 실행을 하면 default 프로파일이 적용되어 옵션이 반영되지 않음을 알 수 있다. 

Spring 공식 문서에 Profile에 관한 설명을 읽어보면, profile을 추가하려면 application.properties 파일에 다음과 같은 문구를 추가하라는 언급이 있다. 

spring.profiles.active=dev,hsqldb
 

Core Features

Spring Boot lets you externalize your configuration so that you can work with the same application code in different environments. You can use a variety of external configuration sources, include Java properties files, YAML files, environment variables, an

docs.spring.io

나의 경우는 local을 추가했고, 다시 실행해보니 제대로 인식되어 적용되는 것을 볼 수 있다.

또는, 명령줄로 실행 시 다음의 옵션을 뒤에 달아줌으로써 프로파일을 적용할 수도 있다.

--spring.profiles.active=local

반응형