Spring Boot - Unable to start web server ? here is the quick fix



Stuck with ApplicationContextException while starting spring boot application ? unable to start servletwebserverapplicationcontext due to missing servletwebserverfactory bean ? Unable to start web server ? getting ERROR o.s.b.SpringApplication - Application run failed error on windows 7 / Windows Vista / Windows 10 ?. Here are the step by step procedure on how to reproduce the issue and fix error.



Springboot Unable to start web server, getting ERROR o.s.b.SpringApplication - Application run failed error



		
		{spring.web.resources.chain.cache=false, spring.web.resources.cache.period=0}

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.0)

2021-04-25 17:48:47 [restartedMain] INFO  c.c.s.r.m.SVClientsApplication - Starting SVClientsApplication using Java 11.0.8 on LTIN226086 with PID 2224 (C:\avi\career\eclipsespacephoton\cts-sv-resource-mgmt\target\classes started by 798582 in C:\avi\career\eclipsespacephoton\cts-sv-resource-mgmt) 
2021-04-25 17:48:47 [restartedMain] DEBUG c.c.s.r.m.SVClientsApplication - Running with Spring Boot v2.4.0, Spring v5.3.1 
2021-04-25 17:48:47 [restartedMain] INFO  c.c.s.r.m.SVClientsApplication - No active profile set, falling back to default profiles: default 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.SpringApplication - Loading source class com.cts.sv.resource.mgmt.SVClientsApplication 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.d.r.ChangeableUrls - Matching URLs for reloading : [file:/C:/avi/career/eclipsespacephoton/cts-sv-resource-mgmt/target/classes/] 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.d.s.DevToolsSettings - Included patterns for restart : [] 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.d.s.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter-[\w-]+/, /spring-boot/(bin|build|out)/, /spring-boot-starter/(bin|build|out)/, /spring-boot-devtools/(bin|build|out)/, /spring-boot-actuator/(bin|build|out)/, /spring-boot-autoconfigure/(bin|build|out)/] 
2021-04-25 17:48:47 [restartedMain] INFO  o.s.b.d.e.DevToolsPropertyDefaultsPostProcessor - Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable 
2021-04-25 17:48:47 [restartedMain] INFO  o.s.b.d.e.DevToolsPropertyDefaultsPostProcessor - For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG' 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2015692d 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerProcessor' 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory' 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor' 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalPersistenceAnnotationProcessor' 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.u.c.s.UiApplicationContextUtils - Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.ResourceBundleThemeSource@50d30170] 
2021-04-25 17:48:47 [restartedMain] WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.d.r.Restarter - Creating new Restarter for thread Thread[main,5,main] 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.d.r.Restarter - Immediately restarting application 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.d.r.Restarter - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@3f7018d9 
2021-04-25 17:48:47 [restartedMain] DEBUG o.s.b.d.r.Restarter - Starting application com.cts.sv.resource.mgmt.SVClientsApplication with URLs [file:/C:/avi/career/eclipsespacephoton/cts-sv-resource-mgmt/target/classes/] 
2021-04-25 17:48:47 [restartedMain] ERROR o.s.b.SpringApplication - Application run failed 
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:582)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
	at com.cts.sv.resource.mgmt.SVClientsApplication.main(SVClientsApplication.java:20)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:209)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:159)
	... 14 common frames omitted



		

Step By Step Procedure to Reproduce - ERROR o.s.b.SpringApplication - Application run failed.



Unable to start web server or , ERROR o.s.b.SpringApplication - Application run failed error occurs when starting the springbott application, this indicates that the springboot app did not start as expected. Unable to start web server error normally occurs when there are multiple exceptions due to missing api's or jars in the classpath.





# Resolving Unable to start web server, ApplicationContextException ERROR



Here is the workaround:
You can try below Solutions:

Solution #1: Make sure all spring starter dependancies are in place.


  • Add all springboot dependancies, viz spring boot starter web..
  • Once dependancies are added, perform maven clean and build if required.
  • Run the spring boot app


<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>



Solution #2: Make sure .m2 directory contains valid springboot jar files.




Autoconfigure Springboot Unable to start web server, getting ERROR o.s.b.SpringApplication - Application run failed error



Solution #3 Just add @EnableAutoConfiguration to main class

Make sure that spring boot main class is annotated with @EnableAutoConfiguration or @SpringBootApplication if you are using latest spring boot version. this might be the reason behind the Exception "Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean"



Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean



Solution #4 For Non Web Application, Disable web application type

For non web application, disable web application type in properties file:



In application.properties:

spring.main.web-application-type=none




For non web application, disable web application type in properties file:



Find more details about ApplicationContextException here:

ApplicationContextException Springboot API doc

Leave a Comment:

 
Ranjin:

I was getting the "unable to start servletwebserverapplicationcontext due to missing servletwebserverfactory bean" error and
"org.springframework.context.applicationcontextexception: unable to start web server" errors,
it was later that i found missing @SpringBootApplication annotation, stupid mistake. but yeah.. it worked like charm after i added @SpringBootApplication.

Cheers!!!


 
Anonymous:

It was different in my case, even after following above solutions i had no luck!!

But i didn't leave it there, tried changing the spirng boot version and tried refreshing the m2 directory and it worked!!!


 
Anonymous:

iam stuck with below error please help


							
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)



 
Anonymous:

I have already added @SpringBootApplication in the starter class, still i am getting below error.

unable to start servletwebserverapplicationcontext due to missing servletwebserverfactory bean.


 
TechX

Make sure spring-boot-starter-web and spring-boot-starter-tomcat dependancies are added in the classpath!


 
Anonymous:

thanks it worked!!


 
smallTed:

Not sure how it worked for you!! i am getting same error if am adding the spring-boot-starter-tomcat dependancy.
everything works fine when i keep only spring-boot-starter-web in my POM.xml.


 
newb:

started to learn spring boot,stuck with very first programm !!


							
Caused by: org.springframework.context.ApplicationContextException: 
Unable to start ServletWebServerApplicationContext due to missing 
ServletWebServerFactory bean.

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext
.getWebServerFactory(ServletWebServerApplicationContext.java:209)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext
.createWebServer(ServletWebServerApplicationContext.java:179)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext
.onRefresh(ServletWebServerApplicationContext.java:159)
... 14 common frames omitted


 
xjx:

refer the stackoverflow post: applicationcontextexception error






Read Next :




x