스프링 프로파일을 사용해서 환경별로 다른 설정이 가능하다 .
* Maven 프로파일 설정과는 별개이므로 주의 Maven 프로파일 설정은 (https://www.lesstif.com/pages/viewpage.action?pageId=14090588) 참조
먼저 properties 파일들을 development 와
spring 환경을 설정하는 방법은 2가지 방법이 있다.
1. 빌드시 전달하는 JVM property
e.g)
java -jar -Dspring.profiles.active=dev
2. web.xml에서 active-profile 설정
<context-param> <param-name>spring.profiles.active</param-name> <param-value>production</param-value> </context-param>
3. catalina.sh 에 직접 설정
JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=local"
4. catalina.properties 에 추가 (D를 빼는 것 주의)
spring.profiles.active=dev
** 중복된 설정 우선순위
현재 삽질하며 확인한 결과 web.xml 을 최우선시하고 tomcat 환경설정에 직접 넣은 값은 값이 있을 경우 무시한다
이제 spring.profiles.active 에 따라 다른 properties 파일을 읽는 설정을 해주어야한다.
아래코드를 응요해서 자신에게 맞는 방법을 선택하자
필자는 development.properties 와 production.properties 를 classpath 아래 두었다.
<bean id="config" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <list> <value>classpath:/#{systemProperties['spring.profiles.active']}.properties </value> </list> </property> </bean>
* 추가팁 로벌 spring 환경 설정 톰캣에서 사용할 경우 설정 방법
1. 이클립스 환경 톰캣에서 지정
참고
1. http://stackoverflow.com/questions/15814497/setting-spring-profile-variable
2. http://jdm.kr/blog/81