프로젝트를 진행하다가 개발환경의 설정파일과 운영환경의 설정파일이 다를 경우
소스에서 if 문으로 분리하거나, 특정 시스템환경 변수값으로 처리하는 방법도 있지만
소스내에 그 부분을 추가하면, 왠지 좀 없어보인다.
이럴 경우 각 환경(개발,운영,테스트)별로 config파일을 나눠서 관리한 후,
maven의 profile을 이용해서 war파일을 build하는 방법이있다.
profile은 적당한 구문으로 나누기 나름
- 개발환경(PC) : local
- 테스트환경( 테스트서버 ) : dev
- 운영환경( 운영서버 ) : real
<build> <resources> <resource> <-- 공통으로 참조하는 config는 여기에 위치 --> <directory>src/main/resources</directory> </resource> <resource> <-- 각 환경별로 이 폴더에 여기에 위치 --> <directory>src/main/resources-${env}</directory> </resource> </resources> </build>
<profiles> <profile> <id>local</id> <activation> <!-- 빌드시 profile값을 안 넣어줄 경우 이 값을 default 하겠다는 의미 --> <activeByDefault>true</activeByDefault> </activation> <properties> <env>local</env> </properties> </profile> <profile> <id>dev</id> <properties> <env>dev</env> </properties> </profile> <profile> <id>real</id> <properties> <env>real</env> </properties> </profile> </profiles>
mvn clean package -P dev