Configure Spring Boot to use Jetty Server

By default, Spring boot uses Tomcat as embedded Web server. There are, however, other available Web servers in case you need some specific features. In this tutorial we will learn how to use Jetty as Web Server.

Add spring-boot-starter-jetty dependency

You will need to update pom.xml and add dependency for spring-boot-starter-jetty. Also, you will need to exclude default added spring-boot-starter-tomcat dependency as follows:

<?xml version="1.0" encoding="UTF-8"?><project>

If you are using Gradle as build tool, the same result can be achieved using:

configurations {
    compile.exclude module: "spring-boot-starter-tomcat"
dependencies {

Configuring Jetty

The Web server can be configured by overriding the default configuration through the file.
####Jetty specific properties########
server.jetty.acceptors= # Number of acceptor threads to use.
server.jetty.max-http-post-size=0 # Maximum size in bytes of the HTTP post or put content.
server.jetty.selectors= # Number of selector threads to use.

Also, you may configure these options programatically using ConfigurableServletWebServerFactory and JettyServletWebServerFactory classes:

  public ConfigurableServletWebServerFactory webServerFactory() {
    JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
    factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notfound.html"));
    return factory;



Found the article helpful? if so please follow us on Socials
Twitter Icon       Facebook Icon       LinkedIn Icon       Mastodon Icon