업무를 하다보면 맡고 있는 홈페이지가 운영인지 개빌인지에 따라 분기처리를 해야하는 경우가 있다.
만약, SpringBoot를 사용한다면 다음 방법을 이용하여 분기처리가 가능하다!
🌱 spring.profiles.active를 이용한 분기처리 (Java)
다음 예시처럼 사용하면 된다.
String profile = System.getProperty("spring.profiles.active");
if(profile == "dev" || profile == "local"){
server_ip = "192.xxx.xx.xx";
}
else if(profile == "real"){
server_ip = "192.xxx.xx.xx";
}
🌱 spring.profiles.active를 이용한 분기처리 (jsp)
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<spring:eval expression="@enviroment.getProperty('spring.profiles.active')" var="activeProfile" />
<c:choose>
<c:when test="${activeProfile eq 'local'}">
<!-- 하고 싶은 분기처리 코드 작성 -->
</c:when>
<c:when test="${activeProfile eq 'dev'}">
<!-- 하고 싶은 분기처리 코드 작성 -->
</c:when>
<c:when test="${activeProfile eq 'real'}">
<!-- 하고 싶은 분기처리 코드 작성 -->
</c:when>
</c:choose>
▶ 위의 코드에서 local, dev, real은 application.yml 파일에서 설정한 것이다.
▶ 각자 설정한대로 쓰면 된다!
enviroment 에서 n 빠져있어요......