Book Image

Spring Boot Cookbook

By : Alex Antonov
Book Image

Spring Boot Cookbook

By: Alex Antonov

Overview of this book

Table of Contents (15 chapters)
Spring Boot Cookbook
Credits
About the Author
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
Index

Choosing embedded servlet containers


Despite Tomcat being the default embedded container in Spring Boot, we are not limited to only one. Spring Boot provides you with ready-to-use starters for Jetty and Undertow as well, so we have a choice of containers.

If we decide that we want to use Jetty as our servlet container, we will need to add a Jetty starter to our build file.

How to do it…

  1. As Tomcat already comes as a transitive dependency of Spring Boot, we will need to exclude it from our build dependency tree by adding the following to build.gradle:

    configurations {
      compile.exclude module: "spring-boot-starter-tomcat"
    }
  2. We will also need to add a compile dependency to our build dependencies on Jetty:

    compile("org.springframework.boot:spring-boot-starter-jetty")
  3. To fix the compiler errors, we will need to remove the bean declaration of Tomcat's RemoteIpFilter from our WebConfiguration class as the Tomcat dependency has been removed.

  4. Start the application by running ./gradlew clean bootRun.

  5. If we...