

Table of Contents
1. Overview
In this example, we will see Spring boot configure undertow server. Spring boot provides an easy way to configure undertow server as like jetty. undertow is web server written in Java and manage and sponsored by JBoss.
Main advantages of undertow are HTTP/2 Support, HTTP Upgrade Support, Web Socket Support, Servlet 4.0, Embeddable, Flexible. here is details explanation of undertow server.
Steps to configure undertow in spring boot application
Step #1 : Exclude spring-boot-starter-tomcat
dependency from spring-boot-starter-web
Step #2: Add spring-boot-starter-undertow
dependency in spring boot.
Improve response performance we can compress server response, here is an article to compress undertow server response.
2. Example
2.1 Maven Application
pom.xml
<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> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> <!-- for spring boot undertow server configuration --> </dependency>
2.2 Gradle Application
build.gradle
dependencies { compile("org.springframework.boot:spring-boot-starter-web") // web application dependency compile("org.springframework.boot:spring-boot-starter-undertow") // for undertow Server } configurations { // exclude Tomcat compile.exclude module: 'spring-boot-starter-tomcat' }
here are some useful properties related to Undertow server, we can configure those properties in application.properties
or application.yml
file.
server.undertow.accesslog.dir= # Undertow access log directory. server.undertow.accesslog.enabled=false # Whether to enable the access log. server.undertow.accesslog.pattern=common # Format pattern for access logs. server.undertow.accesslog.prefix=access_log. # Log file name prefix. server.undertow.accesslog.rotate=true # Whether to enable access log rotation. server.undertow.accesslog.suffix=log # Log file name suffix. server.undertow.buffer-size= # Size of each buffer, in bytes. server.undertow.direct-buffers= # Whether to allocate buffers outside the Java heap. server.undertow.io-threads= # Number of I/O threads to create for the worker. server.undertow.eager-filter-init=true # Whether servlet filters should be initialized on startup. server.undertow.max-http-post-size=0 # Maximum size, in bytes, of the HTTP post content. server.undertow.worker-threads= # Number of worker threads.
3. Concussion
In this article, We have learned how we can configure undertow server in spring boot application. It’s same like Jetty server configuration just differences of dependencies!
4. References
5. Source code
spring-boot-undertow-example (37 KB)