import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class AjaxController {
private static final Logger LOGGER = LoggerFactory.getLogger(AjaxController.class);
@Autowired
private Environment env;
@Value("${spring.profiles.active}")
private String activeProfile;
@RequestMapping(value="/test.do")
public String test() {
System.out.println("test.do ===============================start");
System.out.println("activeProfile================>"+activeProfile);
String sKey = "server.port";
String sVal = env.getProperty(sKey);
System.out.println(sKey + " : " + sVal);
return "helloJson";
}
}
테스트 >>
http://localhost:8090/test.do
test.do ===============================start
activeProfile================>default
server.port : 8090
/*************************************************************
**.application.properties 파일 다른 환경으로 여러개 만들기
*************************************************************
1.파일복사해서 생성
application.properties ==> application-linux.properties
2.tomcat server vm 파라미터 추가
2.1.tomcat server 더블클릭
2.2.Open launch configuration 클릭
2.3.Argument 탭클릭
2.4.VM arguments 에 아래 추가
-Dspring.profiles.active="linux"
(원리 : -D키값=키value)
Profile
'java > Spring Boot' 카테고리의 다른 글
| [Spring Boot 환경파일]build.gradle 작동원리 (0) | 2024.01.09 |
|---|---|
| jasypt 암호화 (0) | 2023.12.11 |
| [build.gradle] dev/prod 분리 (0) | 2023.11.16 |
| [application.properties]default,dev,prod Profile 설정 (0) | 2023.11.16 |
| spring boot devtools 기능 및 적용 (0) | 2023.10.05 |