Know Your Spring Boot Embedded Servlet Container

If you are building a Spring Boot Web App to be launched with an embedded web server like Tomcat or Jetty, it’s nice to know which server you’re using. Not imperative, but good to know.

The Spring documentation on creating a deployable war file does a great job explaining how to add Tomcat or Jetty at runtime. So we configure our app with Tomcat as a ProvidedRuntime library in Gradle. But when we fire-up our Spring Boot app we discover that Jetty has taken over Servlet Container services!

How can this be? We look at our dependencies with Gradle and see that Solr-Core from our Solr Module has called Jetty into play.

With some Dark Java Voodoo we can transfer control back to Tomcat, but we’re going to stick with Jetty and get rid of Tomcat. Both are capable Servlet Containers and less is nearly always more.

First we’ll remove support for Tomcat in the root build.gradle since Spring Boot uses Tomcat by default.

Then we’ll comment out our providedRuntime configuration in the mvc module build.gradle. We’re commenting it out to remind us to include it if our next NixMash Spring-based app doesn’t included Solr!

Source Code Notes for this Post

All source code discussed in this post can be found in my NixMash Spring GitHub repo and viewed online here.