MENUMENU

Spring Boot Jetty Server

In this article of Spring Boot, we will lean how to configure Spring Boot Jetty server.

 

Introduction

Spring Boot web starter use Tomcat as an embedded container by default. This means if we are using the spring-boot-starter-web starter, Spring Boot initialize and start embedded Tomcat server for us. There are times or requirements when we may want to use a different application server. Spring Boot flexible architecture provides options to use a different application server than default one. In this article, we will look in the steps to configure and use Jetty server.

 

1. Spring Boot Jetty

To use Jetty in your Spring Boot application, we can use the spring-boot-starter-jetty starter. Spring Boot provides Tomcat and Jetty dependencies bundled together as separate starters to help make this process as easy as possible. Add the spring-boot-starter-jetty starter in your pom.xml file.

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

Above configuration will add Jetty to your Spring Boot application. Before we move ahead; we need to exclude the default tomcat server from the spring-boot-starter-web starter to avoid the conflict. Use the exclusion tag in your pom.xml for this:

<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-jetty</artifactId>
</dependency>

 

2. Spring Boot Jetty Configurations

Use the application.properties file to customize the behaviour of the Jetty server. Here are few configurations:

server.port=8080
server.servlet.context-path=/home
server.jetty.acceptors=-1 # Number of acceptor threads to use. When the value is -1.
server.jetty.accesslog.append=false # Append to log.
server.jetty.accesslog.date-format=dd/MMM/yyyy:HH:mm:ss Z # Timestamp format of the request log.
server.jetty.accesslog.enabled=false # Enable access log.
server.jetty.accesslog.extended-format=false # Enable extended NCSA format.
server.jetty.accesslog.file-date-format= # Date format to place in a log filename.
server.jetty.accesslog.filename= # Log filename. If not specified, logs redirect to "System.err".
server.jetty.accesslog.locale= # Locale of the request log.
server.jetty.accesslog.log-cookies=false # Enable logging of the request cookies.
server.jetty.accesslog.log-latency=false # Enable logging of request processing time.
server.jetty.accesslog.log-server=false # Enable logging of the request hostname.
server.jetty.accesslog.retention-period=31
server.jetty.accesslog.time-zone=GMT # Timezone of the request log.
server.jetty.max-http-post-size=200000B # Maximum size of the HTTP post or put content.
server.jetty.selectors=-1 # Number of selector threads to use. When the value is -1.

Read our article Spring Boot Web Application Configuration for the Spring Boot application configurations.

 

Summary

In this quick post, we learned how to configure Jetty server in your Spring Boot application. We quickly check how to replace default tomcat server with Jetty in your application.

Umesh

Hello!! I am Umesh- an engineer by profession and a photographer by passion.I like to build stuff on the web using OSS and love to capture the world through my lens.

follow me on:

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of