Spring Boot Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Understanding the EmbeddedWebApplicationContext Issue in Spring Boot
Spring Boot is a powerful framework that simplifies the creation of production-ready applications by packaging them with the necessary infrastructure to deploy. Typically, this involves creating an embedded server with the help of an EmbeddedServletContainerFactory bean, which is an integral part when deploying web applications. Occasionally, developers may encounter an error message that says, "Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean." This article explores this issue in-depth and provides guidance on how to troubleshoot and resolve it.
Understanding the Problem
Spring Boot supports embedding web servers like Tomcat, Jetty, or Undertow, allowing applications to run independently without a necessity for an external web server setup. The EmbeddedServletContainerFactory is a fundamental component that defines how the embedded container should be configured.
When you see the error message regarding the missing EmbeddedServletContainerFactory bean, it typically indicates that Spring Boot has failed to create or locate the necessary components to spin up a web server. Understanding the underlying reasons can help in resolving this issue efficiently.
Common Causes
1. Incorrect Starter Dependencies
The absence of a specific web server dependency in your project can lead to this issue. Spring Boot aims to automatically configure an application based on the dependencies found on the classpath.
Example
If your application is missing a required dependency:
This starter includes the embedded Tomcat server. Without this dependency, Spring Boot won't know how to set up a web server.
2. Incorrect Packaging Type
For web applications, the packaging type should be WAR instead of JAR, especially when deploying to an external server:
When packaging is set to war, embedded server dependence is negated as the archive is configured to be deployed onto an external application server.
3. Misconfiguration in Application Properties
Configuration settings in application.properties or application.yaml files can mislead Spring Boot's auto-configuration:
Ensure that this property is correctly configured, or remove it to let Spring Boot autodetect the environment.
Resolving the Problem
Addressing the missing EmbeddedServletContainerFactory bean requires a keen eye for configuration details. Here are the steps to effectively diagnose and resolve the issue:
Step 1: Check Dependencies
Verify your project’s dependencies to ensure you are using the correct starter for web applications:
Step 2: Validate Packaging
Confirm that the project's packaging type is jar if using an embedded server for standalone deployment:
Step 3: Review Property Settings
Examine the application.properties or application.yaml for any properties that may disable web application startup unintentionally.
Step 4: Confirm Classpath
Ensure that the classpath includes necessary artifacts, especially if using build tools like Maven or Gradle which might omit dependencies unexpectedly due to configuration mistakes.
Conclusion
The "Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean" is a common issue with straightforward solutions. By systematically verifying dependencies, packaging, and configuration settings, developers can swiftly restore functionality to their Spring Boot applications. Understanding the interactions between these components will assist in avoiding similar issues in future applications.
Here is a summary of the key points covered in the article:
| Key Consideration | Description |
| Dependencies | Ensure the presence of spring-boot-starter-web in the build configuration. |
| Packaging Type | Verify that the packaging type is set to jar for embedded web applications. |
| Application Properties | Check misconfigurations that might disable web startup |
| Classpath | Confirm the classpath includes all necessary dependencies for the application |
Through careful attention to these areas, deploying Spring Boot web applications becomes more predictable and resilient against common misconfigurations.
Related reading
- Spring Boot Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean
- Spring Boot Unit Test Autowired
- Spring Boot Unit Test ignores logging.level
- Spring Boot Unit Tests with JWT Token Security
- Spring Boot use of Maven properties configured in yaml
- Spring boot validation annotations Valid and NotBlank not working
- Spring Boot Value Properties
- Spring Boot version versus Spring Framework version?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.