Choosing embedded servlet 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...
- 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 tobuild.gradle
:
configurations { compile.exclude module: "spring-boot-starter-tomcat" }
- We will also need to add a
compile
dependency to ourbuild
dependencies on Jetty:
compile("org.springframework.boot:spring-boot-starter-jetty")
- To fix the compiler errors, we will need to remove the bean declaration of Tomcat's
RemoteIpFilter
from ourWebConfiguration
class, as the Tomcat dependency has been removed. - Start the application by running
./gradlew clean bootRun
- If we now look at the console logs, we will see that our application is running in Jetty:
2017-12-16 --- o.eclipse.jetty.server.AbstractConnector : Started ServerConnector...2017-12-16 ---.o.s.b.web.embedded.jetty.JettyWebServer...