Spring Boot Undertow

last modified July 6, 2020

Spring Boot Undertow tutorial shows how to use Undertow server in a Spring Boot application.

Spring is a popular Java application framework and Spring Boot is an evolution of Spring that helps create stand-alone, production-grade Spring based applications easily.


Undertow is a flexible performant web server which provides both blocking and non-blocking API's. It comes from the JBoss project.

Spring Boot Undertow example

By default, Spring Boot uses a Tomcat embedded web server. The following example shows how to use Undertow.

│   ├───java
│   │   └───com
│   │       └───zetcode
│   │           │   Application.java
│   │           ├───config
│   │           │       AppConfig.java
│   │           └───controller
│   │                   MyController.java
│   └───resources
│           application.properties

This is the project structure.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"











This is the Maven build file. We explicitly exclude the Tomcat server dependency and include the Undertow dependency.

logging.pattern.console=%clr(%d{yy-MM-dd E HH:mm:ss.SSS}){blue} %clr(%-5p) %clr(%logger{0}){blue} %clr(%m){faint}%n

In the application.properties file we have various configuration settings of a Spring Boot application. With the spring.main.banner-mode property we turn off the Spring banner. The logging.pattern.console configures the console logging pattern.

package com.zetcode.controller;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

public class MyController {

    @GetMapping(value="/", produces = MediaType.TEXT_PLAIN_VALUE)
    public String home() {

        return "Home page";

The home page returns a simple text message.

package com.zetcode;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class Application  {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);

The Application is the entry point which sets up Spring Boot application.

$ mvn -q spring-boot:run

We run the application and navigate to localhost:8080.

19-06-28 Fri 17:37:08.557 INFO  nio XNIO NIO Implementation Version 3.3.8.Final
19-06-28 Fri 17:37:08.629 INFO  UndertowServletWebServer Undertow started on port(s) 8080 (http) with context path ''
19-06-28 Fri 17:37:08.634 INFO  Application Started Application in 3.716 seconds (JVM running for 4.352)    

In the console we can see the Undertow server starting.

In this tutorial, we have shown how use Undertow server in a Spring Boot application.

List all Spring Boot tutorials.