배포 서버 별로 Properties 분리해서 사용하기

따용·2023년 4월 10일
0

백엔드

목록 보기
3/4

Properties 파일 관리

배포 서버 별로 조금씩 다른 설정을 여러개의 파일로 관리 및 파일을 수정하고 반복적으로 build를 새로해야 하여 해당 문제를 개선하는 작업을 진행

Properties 파일을 읽는 위치 순서

공식문서
1. A /config subdir of the current directory.
2. The current directory
3. A classpath /config package
4. The classpath root
👉 위 순서대로 우선순위가 높음

Properties 파일 분리

➡️ 파일명은 구분하기 쉽게 배포 방식별로 작성: application-[name].properties
ex) application-dev.properties, application-open.properties

배포 파일 실행시 active 파일 선택

👌 Dspring.profiles.active 옵션을 사용하여 선택

// application.properties
- java -jar webViewer-0.0.1.war

// application-open.properties
- java -jar -Dspring.profiles.active=open webViewer-0.0.1.war

// application-dev.properties
- java -jar -Dspring.profiles.active=dev webViewer-0.0.1.war
profile
🤫

0개의 댓글