Spring boot app 을 bash(또는 cmd, powershell 등)를 통해서 실행 시에
spring.profiles.active 인자를 전달할 수 있습니다.
그런데 이 전달 방법을 제대로 알지 못하면 원하는 동작이 안될 수 있습니다.
한번 이 기회에 제대로 알고 넘어가 보죠. 참고로 여기서 작성된 글은 아래 링크에
있는 내용을 가져온 것입니다.
Setting active profile and config location from command line in spring boot
java -jar -Dspring.profiles.active=prod application.jar
System.getProperty("spring.profiles.active") 로 조회할 수 있습니다.java -jar application.jar --spring.profiles.active=prod --spring.config.location=c:\config
java -jar -D{여기에 VM argument 작성} test.jar {여기에 program argument 작성}
참조한 글이 spring boot 와 관련된 내용이다 보니 program argument 앞에 -- 같은 prefix 는 붙였는데, 이건 어디까진 스프링 애플리케이션 내부에서 -- 를 쓰는 방식을 미리 지정해서 그런 겁니다.
Spring Boot 에서는 이런
--가 붙는 인자를Option Argument라고 합니다.
참고: ApplicationArguments javaDoc
그러므로 단순한 jar 파일 실행 시에는 -- 가 반드시 붙어야 되는게 아닙니다!
만약 vm option 과 program argument 의 명확한 차이를 직접 알고 싶다면
아래 링크를 참조하시기 바랍니다.
참고 링크:
What's the difference between program arguments and VM arguments?