This post will discuss how to resolve the “Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean” error in a Spring Boot.

Following is the complete stack trace of the above error:

Exception in thread “main” org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:140)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:124)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:658)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:355)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:920)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:909)
at hu.kumite.Application.main(Application.java:17)
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:190)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:163)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
… 7 more

We can fix this error in two ways:

 
1. Make sure you have the @SpringBootApplication annotation is placed on your main class.

The @SpringBootApplication annotation is equivalent to @EnableAutoConfiguration, @ComponentScan, and @Configuration annotation with their default attributes, i.e., enable auto-configuration, component scan and allow registering extra beans in the context or import additional configuration classes.

Consider the following example in which the Application.java file declares the main method, along with the @SpringBootApplication annotation:

 
2. If your starter file already contains @SpringBootApplication annotation, make sure you have included spring-boot-starter-web and spring-boot-starter-tomcat dependencies in your pom.xml, as shown in the following example:

That’s all about resolving the “Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean” error in a Spring Boot.