spring-boot服务启动报: Unable to start embedded container
2018-03-25 16:12
991 查看
初次接触spring-boot + spring-cloud构建微服务项目,配置好项目后并选择启动类启动时报如下错误:
[main] ERROR org.springframework.boot.SpringApplication - Application startup failed
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:137)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at com.dispatchCenter.main.DispatchCenterApplication.main(DispatchCenterApplication.java:9)
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:189)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)
... 8 common frames omitted
1、根据报错信息发现是在刷新容器的方法onRefresh中抛出的,为什么是刷新容器的方法呢?相信大家都知道spring-boot是基于spring的扩展,是简化spring配置的一个工具,
至于spring是怎么初始化的在本篇不做概述。我们在这只需要知道EmbeddedWebApplicationContext extends org.springframework.web.context.support.GenericWebApplicationContext。
下面点进去查看EmbeddedWebApplicationContext此类中刷新容器的方法的源码如下: protected void onRefresh() {
super.onRefresh(); --这里就是刷新spring容器的入口
try {
this.createEmbeddedServletContainer(); --捕获的是这个方法中的异常
} catch (Throwable var2) {
throw new ApplicationContextException("Unable to start embedded container", var2); --这里捕获异常后抛出
}
}2、接着被捕获异常的方法源码:private void createEmbeddedServletContainer() {
EmbeddedServletContainer localContainer = this.embeddedServletContainer;
ServletContext localServletContext = this.getServletContext();
if (localContainer == null && localServletContext == null) {
EmbeddedServletContainerFactory containerFactory = this.getEmbeddedServletContainerFactory(); --根据报错信息这里抛出的异常
this.embeddedServletContainer = containerFactory.getEmbeddedServletContainer(new ServletContextInitializer[]{this.getSelfInitializer()});
} else if (localServletContext != null) {
try {
this.getSelfInitializer().onStartup(localServletContext);
} catch (ServletException var4) {
throw new ApplicationContextException("Cannot initialize servlet context", var4);
}
}
this.initPropertySources();
}3、再接着就是抛出异常的根源所在的源码,通过查看源码得出是启动时从beanFactory中找不到所需bean的存在,也就是bean根本没有注册:protected EmbeddedServletContainerFactory getEmbeddedServletContainerFactory() {
String[] beanNames = this.getBeanFactory().getBeanNamesForType(EmbeddedServletContainerFactory.class); --这里通过类型去查询bean,结果发现一个都没有就抛出异常了,当然如果超过一个也会抛出异常
if (beanNames.length == 0) {
throw new ApplicationContextException("Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.");
} else if (beanNames.length > 1) {
throw new ApplicationContextException("Unable to start EmbeddedWebApplicationContext due to multiple EmbeddedServletContainerFactory beans : " + StringUtils.arrayToCommaDelimitedString(beanNames));
} else {
return (EmbeddedServletContainerFactory)this.getBeanFactory().getBean(beanNames[0], EmbeddedServletContainerFactory.class);
}
}4、知道原因了反过去查看代码发现启动类中少写了注解,太粗心大意了
@EnableEurekaServer
@SpringBootApplication
5、还有一种情况需要注意,我们使用注解标注了这个启动类,但是还是提示Cannot resolve symbol *等问题,一定要去检查引包是否正确
[main] ERROR org.springframework.boot.SpringApplication - Application startup failed
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:137)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at com.dispatchCenter.main.DispatchCenterApplication.main(DispatchCenterApplication.java:9)
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:189)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)
... 8 common frames omitted
1、根据报错信息发现是在刷新容器的方法onRefresh中抛出的,为什么是刷新容器的方法呢?相信大家都知道spring-boot是基于spring的扩展,是简化spring配置的一个工具,
至于spring是怎么初始化的在本篇不做概述。我们在这只需要知道EmbeddedWebApplicationContext extends org.springframework.web.context.support.GenericWebApplicationContext。
下面点进去查看EmbeddedWebApplicationContext此类中刷新容器的方法的源码如下: protected void onRefresh() {
super.onRefresh(); --这里就是刷新spring容器的入口
try {
this.createEmbeddedServletContainer(); --捕获的是这个方法中的异常
} catch (Throwable var2) {
throw new ApplicationContextException("Unable to start embedded container", var2); --这里捕获异常后抛出
}
}2、接着被捕获异常的方法源码:private void createEmbeddedServletContainer() {
EmbeddedServletContainer localContainer = this.embeddedServletContainer;
ServletContext localServletContext = this.getServletContext();
if (localContainer == null && localServletContext == null) {
EmbeddedServletContainerFactory containerFactory = this.getEmbeddedServletContainerFactory(); --根据报错信息这里抛出的异常
this.embeddedServletContainer = containerFactory.getEmbeddedServletContainer(new ServletContextInitializer[]{this.getSelfInitializer()});
} else if (localServletContext != null) {
try {
this.getSelfInitializer().onStartup(localServletContext);
} catch (ServletException var4) {
throw new ApplicationContextException("Cannot initialize servlet context", var4);
}
}
this.initPropertySources();
}3、再接着就是抛出异常的根源所在的源码,通过查看源码得出是启动时从beanFactory中找不到所需bean的存在,也就是bean根本没有注册:protected EmbeddedServletContainerFactory getEmbeddedServletContainerFactory() {
String[] beanNames = this.getBeanFactory().getBeanNamesForType(EmbeddedServletContainerFactory.class); --这里通过类型去查询bean,结果发现一个都没有就抛出异常了,当然如果超过一个也会抛出异常
if (beanNames.length == 0) {
throw new ApplicationContextException("Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.");
} else if (beanNames.length > 1) {
throw new ApplicationContextException("Unable to start EmbeddedWebApplicationContext due to multiple EmbeddedServletContainerFactory beans : " + StringUtils.arrayToCommaDelimitedString(beanNames));
} else {
return (EmbeddedServletContainerFactory)this.getBeanFactory().getBean(beanNames[0], EmbeddedServletContainerFactory.class);
}
}4、知道原因了反过去查看代码发现启动类中少写了注解,太粗心大意了
@EnableEurekaServer
@SpringBootApplication
5、还有一种情况需要注意,我们使用注解标注了这个启动类,但是还是提示Cannot resolve symbol *等问题,一定要去检查引包是否正确
相关文章推荐
- SpringbootUnable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFact
- Spring boot多模块(moudle)中的一个注入错误(Unable to start embedded container; nested exception is org)
- SpringBoot 启动报错:Unable to start embedded
- IDEA启动spring boot 出现Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCont
- Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFa
- 关于新建SpringBoot项目添加Myeclipse Service Library 之后项目就报错Unable to start embedded container;
- spring boot 报错 Unable to start embedded container;
- 从eclipse中导入到IDEA中的SpringBoot项目,启动时报错 Unable to start EmbeddedWebApplicationContext due to missing Em
- Spring Boot错误:Unable to start embedded container...的问题解决
- Spring Boot常见问题(二)Unable to start embedded container; nested exception is java.lang.NoSuchMethodErro
- IDEA启动Spring Boot项目提示Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServlet...
- IDEA执行spring boot 出现Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCont
- SpringBoot启动报错" Unable to start embedded container; nested exception is org.springframework.beans.fa
- 在springboot中配置https安装证书 Unable to Start embedded TomCat
- Spring Boot jar 启动错误“due to missing embeddedServletContainerFactory.bean”
- org.springframework.context.ApplicationContextException: Unable to start embedded container; nested
- 关于spring boot org.springframework.context.ApplicationContextException:Unable to start Embedded解决方案
- SpringBoot - Unable to Start embedded TomCat
- Spring Cloud | Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainer
- SpringBoot - Unable to Start embedded TomCat