SpringBoot 서버별 properties 분리 방법 / IntelliJ Gradle war 빌드 방법

SpringBoot 서버별 properties 분리 방법

application.properties 분리 예시

구분 properties 파일명 프로파일명
개발서버용 application.properties prod (없음)
운영서버용 application-real.properties real
로컬테스트용 application-local.properties local

properties 파일 경로

프로젝트폴더/src/main/resources

IntelliJ에서 properties 파일 변경하여 내장 톰캣 실행 방법

우측 상단 ‘프로젝트명Application’ 클릭 > Edit Configuration… > Active profiles 수정 (운영서버용 예시 : real) > Apply > Run ‘프로젝트명Application’

리눅스 톰캣에 운영서버용 properties 사용을 위한 환경변수 파일 생성

vi /톰캣경로/bin/setenv.sh

환경변수 파일 내용을 아래와 같이 입력하여 생성해두면, 톰캣 재시작 시 자동으로 properties 파일이 변경되어 적용됩니다.

JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=real"

IntelliJ Gradle war 빌드 방법

우측 Gradle 메뉴 > 프로젝트명 > Tasks > build > bootWar 더블클릭 > ‘BUILD SUCCESSFUL’ 로그 확인

war 파일 위치
프로젝트폴더/build/libs 폴더에 ‘프로젝트명-GradleVersion명.war’ 파일이 생성됩니다.

기존 build 폴더 삭제 (Clean)
우측 Gradle 메뉴 > 프로젝트명 > Tasks > build > clean 더블클릭

Leave a comment