[Spring] Spring Boot fully executable jar 로 배포할때 주의사항

스프링 부트는 war 또는 jar 로 배포 가능하다.

jar의 경우 톰캣을 내장하여 jar파일 하나로 서비스가 가능하다. 게다가 fully executable application으로 만드는 것도 가능하다. 다른 executable binary 처럼 리눅스의 init.d나 systemd에 서비스로 등록되어 제어가능하다는 이야기이다. fully executable jar로 만들기 위해서는 maven이나 gradle 설정파일에 설정을 추가해주면 된다.

maven의 경우,

<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<configuration>
		<executable>true</executable>
	</configuration>
</plugin>

를 pom.xml에 추가해준다.

gradle의 경우,

springBoot {
    executable = true
}

를 build.gradle 파일에 추가해 준다. 참고로 Spring boot 2.0버전부터는 위 설정 대신 아래의 설정으로 대체된 것 같다.

bootJar {
    launchScript()
}

자세한 방법은 아래 공식 문서에 자세히 나와있다.

https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html

스프링 부트를 이용한 배포는 매우 편리하다. Micro Service Architecture를 위해 만들어진게 아닌가 싶다. 이렇게 편리한 스프링 부트이지만 실제 서비스에 배포할때 몇가지 삽질했던 부분이 있어 글로 남긴다.

먼저 로컬에서 실행할때는 encoding이 utf-8로 잘 적용되어 로그가 정상적으로 남았는데 실제 리눅스(centos) 에 배포했을때에는 아래와 같이 한글로그가 깨졌다.

문제는 리눅스의 systemd(service)에 있었다. 아래 스택오버플로우 글을 참고하자.

https://stackoverflow.com/questions/39163590/how-to-set-utf-8-character-encoding-in-spring-boot

해결책은 jar파일이 있는 경로에 jar파일과 같은 이름으로 .conf 파일을 만들고 아래 한줄을 추가해주면 된다.

export LANG='ko_KR.UTF-8'

또 한가지 겪었던 이슈는 파일 생성이다.

The temporary upload location [/tmp/tomcat.1569213510584817208.8080/work/Tomcat/localhost/ROOT] is not valid

위와 같은 에러가 뜨면서 Spring application 내에서 파일 생성이 안되었다.  아래와 같이 application.yml에 embeded tomcat의 basedir을 설정해 주어 해결되었다.

server:
  tomcat:
    basedir: /data/tomcat-base

자세한 내용은 아래 링크에 설명되어 있다.

https://tridion.stackexchange.com/questions/14324/temporary-upload-location-is-not-valid/16831

배포 방식이 달라  생기는 이슈들이 좀 있기는 하지만 그래도 스프링 부트는 장점이 어마무시하다.

누군가의 글에서 읽은 아래 글귀가 너무 공감이 간다.

스프링 부트는 사랑입니다.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다