TomcatEmbeddedServletContainerFactory is missing in Spring Boot 2
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Spring Boot has been a game-changer for Java developers, offering a streamlined approach to application creation with its opinionated setup. Older versions of Spring Boot provided developers with various tools and classes to set up and customize embedded servlet containers such as Tomcat. One such class was the TomcatEmbeddedServletContainerFactory, popular for its simplicity and ease of use. However, with the release of Spring Boot 2, this class and others like it were deprecated. Let's explore what this change entails and how to handle embedded server configuration in the latest versions.
Transition from Spring Boot 1.x to 2.x
In Spring Boot 1.x, TomcatEmbeddedServletContainerFactory provided extensive support for customizing the embedded Tomcat server. This factory class was part of the traditional way of bootstrapping and customizing an embedded web server in a Spring Boot application.
Migration of Concepts
With Spring Boot 2.x, there was a major overhaul of server configuration capabilities. The primary class for this purpose, TomcatEmbeddedServletContainerFactory, was removed in favor of a more generic and streamlined hierarchy:
- Spring Boot 1.x:
TomcatEmbeddedServletContainerFactory - Spring Boot 2.x:
TomcatServletWebServerFactory
Example of the Change
Here's an example that demonstrates the difference between configuring embedded Tomcat in Spring Boot 1.x and 2.x.
Spring Boot 1.x:
Spring Boot 2.x:
Key Changes and Improvements
The new class and package structure in Spring Boot 2.x brought several improvements, notably:
- Unified Server Configuration: The creation and customization of servlet web servers are now more straightforward and unified across different types of containers using the
ServletWebServerFactoryinterface. This promotes better abstraction and consistency. - Enhanced Flexibility: Developers have greater control and flexibility by defining beans of type
TomcatServletWebServerFactory, which can be injected and customized as needed using factory methods. - Centralized Properties: Server settings are increasingly controlled via properties in
application.propertiesorapplication.yml, reducing the need for extensive Java configuration.
Configuration Using Properties
A significant shift in Spring Boot 2.x is the reliance on configuration files for server settings. This removes much of the boilerplate Java code and simplifies server customization.
Example application.properties:
Summary of Key Changes
To quickly recap the evolution from Spring Boot 1.x to 2.x, refer to the table below:
| Feature/Package | Spring Boot 1.x | Spring Boot 2.x |
| Tomcat Factory Class | TomcatEmbeddedServletContainerFactory | TomcatServletWebServerFactory |
| Package | org.springframework.boot.context.embedded.tomcat | org.springframework.boot.web.embedded.tomcat |
| HTTP/2 Support | Limited | Enhanced |
| Server Configuration Method | Predominantly Java Code | Combination of Java & Configuration files |
| Configuration Flexibility | Code-based extensions | Property & Bean-based customization |
Best Practices for Transition
If you're planning to upgrade your Spring Boot application or start a new project, keep the following practices in mind:
- Leverage Configuration Files: Maximize the use of
application.propertiesorapplication.ymlfor overriding default settings. - Simplify: Utilize the updated Spring Boot 2.x capabilities for server configuration to reduce the complexity of configuration classes.
- Stay Informed: Keep abreast of the latest Spring Boot releases and their respective documentation to anticipate and make the most out of new features.
Conclusion
The removal of TomcatEmbeddedServletContainerFactory from Spring Boot 2.x marks a move towards a more robust, scalable, and developer-friendly approach to embedding servers. By embracing these changes, developers can enjoy an architecture that is both cleaner and more powerful, with a reduced emphasis on boilerplate code, making way for greater focus on application logic.
Related reading
- Trick to loop/autorefresh docker ps view like top/htop in bash
- Trying to start the kubernetes in Docker-Desktop but it's stuck
- UDP send and receive in kubernetes
- Unable to access my minikube cluster from the browser ❗ Because you are using a Docker driver on windows, the terminal needs to be open to run it.
- Transaction synchronization in Spring Boot
- Transactional annotation not working in Spring Boot
- Unable to connect to mongoDB running in docker container
- Unable to get a shell into citadel container in kubernetes

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.