Spring Boot: Changing/Configuring the Default Embedded Server

DZone 's Guide to

Spring Boot: Changing/Configuring the Default Embedded Server

In this post we take a look at how to set and configure the default embedded web server used in your Spring Boot application.

· Java Zone ·
Free Resource

In a previous post, we created a web-based Spring Boot application that uses Embedded Tomcat as the default server running on the default port, 8080. Spring Boot supports Tomcat, Undertow, and Jetty as embedded servers. Now, we will change and/or configure the default embedded server and common properties to all the available servers.

Spring Boot provides a convenient way of configuring dependencies with its starters. For changing the embedded server, we will user its spring-boot-starter-undertow.

Adding Dependencies


spring-boot-starter-web comes with Embedded Tomcat. We need to exclude this dependency.


This is all we need to do to change the embedded server. There are some generic properties that are applicable for every server, and some server-specific properties that we can tweak to improve performance. Let's change some of the server properties.

Changing the Default Server Port

The server.port property is used for configuring the port on which our Spring Boot application should run.

Enabling Compression on Responses

You can enable compression on responses sent by the server and can tweak the mimeTypes, and minResponseSize for compression. By default, compression is disabled. The default property value for mimeTypes is: text/html, text/xml, text/plain, text/css, text/javascript,

application/javascript. The default value for minResponseSize is 2048 bytes.

Other Server Properties

You can also enable SSL, modify maxHttpPostSize, contextParameters, contextPath , and other server-related properties. To know more, see the org.springframework.boot.autoconfigure.web.ServerProperties class.

Configuring Server-Specific Properties

You can also change embedded server-specific properties. In our example, we changed the embedded server to Undertow and tweaked its ioThreads and workerThreads properties.

A sample properties file, which have the above property changes, would look like so:

  port: 8082
    ioThreads: 15
    workerThreads: 150
      enabled: true
    enabled: true
    mimeTypes: text/xml, text/css, text/html, application/json
    minResponseSize: 4096

    name: gaurav-bytes-embedded-server-example

I hope this article is informative and helpful. You can grab the full example code on Github.

configuration, embedded servers, java, spring boot, tutorial

Published at DZone with permission of Gaurav Rai Mazra , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}