您的位置:首页 > 移动开发 > WebAPP

Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFa

2017-03-18 16:51 357 查看
使用springboot的时候,通过点击点击Application类中的类方法直接运行的时候一直报以下错误:

2017-03-18 17:03:23.212 ERROR 11488 --- [ main] o.s.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) ~[spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372) [spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187) [spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176) [spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at com.riyun.test.AmqpApplication.main(AmqpApplication.java:17) [classes/:na]
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) ~[spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) ~[spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.5.RELEASE.jar:1.4.5.RELEASE]
... 8 common frames omitted

问题搞了好几个小时,网上的各种方法都试过了。最后居然排查到时因为版本的原因。

场景:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.5.RELEASE</version>
</parent>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
找问题的时候,通过这篇文章的:http://stackoverflow.com/questions/21783391/spring-boot-unable-to-start-embeddedwebapplicationcontext-due-to-missing-embedd?rq=1

看到有个老外说在代码中强制声明一个EmbeddedServletContainerFactory,代码如下:
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory =
new TomcatEmbeddedServletContainerFactory();
return factory;
}
强制声明之后,就报错说jetty所需jdk版本不对,顿时茅塞顿开。因为工程中默认使用的jetty版本是9.3的版本,而这个的jetty版本是需要jdk1.8的,我本机是1.7。问题原因找到了,解决办法也就有了

第一个办法:降低springboot的版本

第二个办法:强制声明jetty的版本为本机jdk适配的,如我本机jdk为1.7,那我强制声明jett的版本为:
<jetty.version>9.2.17.v20160517</jetty.version>
第三个办法:把自己本机的jdk升级到1.8吧。

花了几个小时,哎。最后吐槽下,报错信息能不能精确点呢。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐