티스토리 뷰

EN/JAVA

[SpringBoot] Apply & Deploy Undertow

개발개 2019. 8. 12. 14:48
728x90

 

Hello, this is Dev_dog.

 

In this post, We're going to figure out

how to apply and deploy the officially supported embedded server 'UNDERTOW'.


If you find any errors or have any questions, feel free.

 

 한글 포스트는 아래 링크에서 보실 수 있습니다 : 

[KR/JAVA] - [SpringBoot] Undertow 적용 및 배포

 

 

 


 

What is 'undertow'?

  • Ultralight & High Performance Web Server
  • Provide NIO-based blocking / nonblocking API
  • Implemented in Java, available to all JVM-based applications in embedded mode

 


 

Development Environment

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

 

 


 

How to apply 'undertow'

It's easy. Let's modify pom.xml.

 

Original

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

 

Modified

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    
    <!-- Exclude embedded Tomcat server -->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<!-- Add undertow -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

 

To reflect the modified 'pom.xml',
Right click on the project > Maven > Project Update
(Stop if it's running) Then, run it with Spring Boot App .

 

You can check the logs like below.

Tomcat → undertow

 

Original

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)

 

Modified

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'

 

 


 

 

How to deploy 'undertow'

Add maven-shade-plugin to make it a runnable jar.

 

Origianl

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

 

Modified

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

        <!--Add maven-shade-plugin for a runnable jar -->
        <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>

 

Reflect the modified pom.xml in the following order.
Right-click Project> Maven> Project Update

Create a runnable jar in the following way:
Right-click Project> Run As> Run Configurations> Right-click Maven Build> New configuration
Find Base difrectory: Workspace ... and register your current project
Goals: clean package
Apply> Run

 

If you check the target folder in the actual project directory, a jar file is created.

In my case, D:\workspace_sts\PRODUCT_API\target\PRODUCT_API-0.0.1-SNAPSHOT.jar

 

 


 

Local Test

Move only the jar file to another directory.

 

using PowerShell

Click in the directory where the jar is located > Open PowerShell here

java -jar .\PRODUCT_API-0.0.1-SNAPSHOT.jar

 

using Command(cmd)

Windows Key+R > cmd > move to the directory where the jar is located

java -jar PRODUCT_API-0.0.1-SNAPSHOT.jar

 

After it runs, you can test your API using browsers, Postman, etc...

http://localhost:8080/products?pubNum=08888881&pubNum=08888882

 

 

 


 

 

This post was written with the following references.

http://undertow.io/

 

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

 

728x90
Total
Today
Yesterday
«   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
04-30 00:02