1. Overview

Spring boot provides default tomcat as web container but also provide spring boot jetty server configuration using Maven or Gradle.

Steps to configure jetty in spring boot application

Step #1 : Exclude spring-boot-starter-tomcat dependency from spring-boot-starter-web

Step #2: Add spring-boot-starter-jetty dependency in spring boot.

2. Example

2.1 pom.xml

<dependencies>
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-web</artifactId>
           <exclusions>
               <!-- Exclude the Tomcat dependency -->
               <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>   <!-- for spring boot jetty server configuration  -->
       </dependency>
   </dependencies>

2.2 build.gradle

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")     // web application dependency
    compile("org.springframework.boot:spring-boot-starter-jetty")    // for Jetty Server
}

configurations {
    // exclude Tomcat
    compile.exclude module: 'spring-boot-starter-tomcat'
}

At startup, it will display the following log when application start:

2017-07-29 13:20:17.344  INFO 38284 --- [           main] o.e.jetty.server.AbstractConnector       : Started [email protected]{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2017-07-29 13:20:17.347  INFO 38284 --- [           main] .s.b.c.e.j.JettyEmbeddedServletContainer : Jetty started on port(s) 8080 (http/1.1)
2017-07-29 13:20:17.354  INFO 38284 --- [           main] com.javadeveloperzone.SpringBootConfig   : Started SpringBootConfig in 4.536 seconds (JVM running for 5.263)

2.2 Spring Boot provides following configuration for the jetty server

server.jetty.acceptors= # Number of acceptor threads to use.
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 log file name.
server.jetty.accesslog.filename= # Log filename. If not specified, logs will be redirected 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 # Number of days before rotated log files are deleted.
server.jetty.accesslog.time-zone=GMT # Timezone of the request log.
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.

3. References

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Yes
No

Leave a Reply

Your email address will not be published. Required fields are marked *