티스토리 뷰
안녕하세요. 개발개입니다.
이번 글에서는 Springboot 공식 지원 내장 서버인
Undertow의 적용 및 배포에 대해 알아보도록 하겠습니다.
오타, 오류 혹은 기타 의견은 언제든지 환영합니다.
You can also read this post in English via the link below :
[EN/JAVA] - [SpringBoot] Apply & Deploy Undertow
undertow란?
- 초경량 & 고성능 웹 서버
- NIO 기반의 블로킹/논블로킹 API 제공
- Java로 구현되어 임베디드 모드의 모든 JVM 기반 응용 프로그램에서 사용 가능
개발환경 |
Windows 10 STS 3.9.6 jdk 1.8 spring-boot 2.1.6 ORACLE (ojdbc9 11.2.0.3) MyBatis 2.1.0 Lombok Maven |
undertow 적용 방법
간단합니다. pom.xml을 수정합니다.
기존
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
변경 후
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 기본 내장 톰캣 제외 -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- undertow 추가 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
수정한 pom.xml을 반영하기 위하여
프로젝트 우클릭 > Maven > Project Update를 해준 후,
(기존 실행이 있다면 정지하고) Spring Boot App으로 실행합니다.
다음과 같은 로그를 확인할 수 있습니다.
Tomcat → undertow
기존
2019-08-08 17:19:58.494 INFO 18444 --- [ main] tistory.thedev.api.ProductApiApplication : Starting ProductApiApplication on DEV with PID 18444 (D:\workspace_sts\PRODUCT_API\target\classes started by THEDEV in D:\workspace_sts\PRODUCT_API)
2019-08-08 17:19:58.496 DEBUG 18444 --- [ main] tistory.thedev.api.ProductApiApplication : Running with Spring Boot v2.1.6.RELEASE, Spring v5.1.8.RELEASE
2019-08-08 17:19:58.496 INFO 18444 --- [ main] tistory.thedev.api.ProductApiApplication : No active profile set, falling back to default profiles: default
2019-08-08 17:19:59.136 INFO 18444 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-08 17:19:59.136 INFO 18444 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-08-08 17:19:59.195 INFO 18444 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-08 17:19:59.626 INFO 18444 --- [ main] tistory.thedev.api.ProductApiApplication : Started ProductApiApplication in 1.389 seconds (JVM running for 1.798)
변경 후
2019-08-08 16:04:05.969 INFO 24268 --- [ main] tistory.thedev.api.ProductApiApplication : Starting ProductApiApplication on DEV with PID 24268 (D:\workspace_sts\PRODUCT_API\target\classes started by THEDEV in D:\workspace_sts\PRODUCT_API)
2019-08-08 16:04:06.585 DEBUG 24268 --- [ main] tistory.thedev.api.ProductApiApplication : Running with Spring Boot v2.1.6.RELEASE, Spring v5.1.8.RELEASE
2019-08-08 16:04:06.586 INFO 24268 --- [ main] tistory.thedev.api.ProductApiApplication : No active profile set, falling back to default profiles: default
2019-08-08 16:04:07.183 WARN 24268 --- [ main] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2019-08-08 16:04:07.201 INFO 24268 --- [ main] io.undertow.servlet : Initializing Spring embedded WebApplicationContext
2019-08-08 16:04:07.618 INFO 24268 --- [ main] org.xnio : XNIO version 3.3.8.Final
2019-08-08 16:04:07.625 INFO 24268 --- [ main] org.xnio.nio : XNIO NIO Implementation Version 3.3.8.Final
2019-08-08 16:04:07.696 INFO 24268 --- [ main] tistory.thedev.api.ProductApiApplication : Started ProductApiApplication in 1.994 seconds (JVM running for 5.839)
2019-08-08 16:05:24.974 INFO 24268 --- [ XNIO-1 task-1] io.undertow.servlet : Initializing Spring DispatcherServlet 'dispatcherServlet'
배포 방법
runnable jar로 만들기 위해 pom.xml에 maven-shade-plugin을 추가합니다.
기존
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
변경
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- runnable jar를 위한 maven-shade-plugin 추가 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
수정한 pom.xml을 다음의 순서로 반영합니다.
프로젝트 우클릭 > Maven > Project Update
runnable jar를 다음의 방법으로 생성합니다.
프로젝트 우클릭 > Run As > Run Configurations > Maven Build... > New configuration
Base difrectory: Workspace...로 찾아서 현재 프로젝트 등록
Goals: clean package
Apply > Run
실제 프로젝트 디렉터리 내 target 폴더에 들어가면 jar파일이 생성되어 있습니다.
제 경우, D:\workspace_sts\PRODUCT_API\target\PRODUCT_API-0.0.1-SNAPSHOT.jar
로컬에서 단독 실행 테스트
jar 파일만 다른 디렉터리로 옮깁니다.
PowerShell을 이용하는 경우
jar가 있는 디렉터리에서 Shift + 우클릭 > 여기에 PowerShell창 열기
java -jar .\PRODUCT_API-0.0.1-SNAPSHOT.jar
Command(cmd)를 이용하는 경우
윈도우키+R > cmd > 옮긴 디렉터리로 이동
java -jar PRODUCT_API-0.0.1-SNAPSHOT.jar
구동이 되었으면 API 테스트 툴이나 브라우저를 통해 테스트합니다.
http://localhost:8080/products?pubNum=08888881&pubNum=08888882
본 글은 다음을 참고하여 작성되었습니다.
Undertow · JBoss Community
Ok then. Here is a simple Hello World server using Async IO: public class HelloWorldServer { public static void main(final String[] args) { Undertow server = Undertow.builder() .addHttpListener(8080, "localhost") .setHandler(new HttpHandler() { @Override p
undertow.io
https://zepinos.tistory.com/35
Spring Boot 공식 지원 내장 WAS 인 Undertow 을 씁시다.
Java 가 Web 개발에서 두각을 나타내면서 WAS(Web Application Server) 라는 용어를 널리 사용하게 만들었습니다. 처음의 의도와 달리 WAS 을 지칭하는 의미는 점차 확대되었고, Java 에서는 Apache Tomcat(이하 T..
zepinos.tistory.com
https://www.daleseo.com/spring-boot-embedded-server-change/
스프링 부트 내장 서버 바꾸기
본 포스트에서는 스프링 부트의 내장 서버를 바꾸는 방법에 대해서 알아보도록 하겠습니다. 메이븐 설정 파일(pom.xml)만 조금씩 수정해주면 다양한 내장 서버를 사용해볼 수 있습니다. Tomcat스프링 부트는 디플트 내장 서버로 Tomcat을 사용하고 있습니다. 따라서 특별한 설정없이 Web Starter 의존성만 추가해주면 됩니다. 1234<depe< p=""> </depe<>
www.daleseo.com
https://www.baeldung.com/jboss-undertow
Introduction to JBoss Undertow | Baeldung
Discover Undertow - an extremely lightweight and high-performance web server from JBoss.
www.baeldung.com
'KR > Java' 카테고리의 다른 글
놓치기 쉬운 자바(JAVA) : (3) java.lang 패키지 (0) | 2021.06.11 |
---|---|
놓치기 쉬운 자바(JAVA) : (2) 객체지향 (0) | 2021.04.22 |
놓치기 쉬운 자바(JAVA) : (1) 기초개념 (0) | 2021.04.22 |
[Lombok] 롬복 설치 및 STS(eclipse) 연동하기 (1) | 2020.02.28 |
[Spring] 스프링 프레임워크(Spring Framework)를 사용하는 이유 (0) | 2019.10.02 |