티스토리 뷰

최근에 이 글을 작성하면서 Spring 애플리케이션을 jar로 실행시 Java RunTime 시점에 System 변수를 주입하는법에 대해 정리를 해보았는데 이번엔 jar가 아닌 war로 배포할때 Java System변수를 추가하는법에 대해 알아보자.

IDE에서 구동

Eclipse나 STS에서 구동할때 Server 탭 > Tomcat Server 클릭 > Open launch configuration 클릭 > Arguments 탭 클릭하게되면 VM arguments란에 -Dname=value를 작성해주면 된다.



Tomcat을 구동하게되면 Console에 해당 시스템변수가 주입된걸 볼 수 있으며 System.getProperty(key) 메서드로 확인해보니 정상적으로 출력되었다.



Tomcat Directory

Tomcat이 설치된 경로의 conf/catalina.properties에 들어가서 시스템변수를 추가해준다. 이때 -D는 적지않고 name=value만 적어준다.



war로 빌드한 뒤 log를 심어 값이 정상적으로 찍히는지 확인해보자.



정상적으로 System 변수가 주입된걸 확인할 수 있다.

 

 

 

 

 

Apache Tomcat 9 Configuration Reference (9.0.45) - Overview

This manual contains reference information about all of the configuration directives that can be included in a conf/server.xml file to configure the behavior of the Tomcat Servlet/JSP container. It does not attempt to describe which configuration directive

tomcat.apache.org

공식문서 참고

728x90
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함