異常全文如下:
- 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.4.RELEASE.jar:1.4.4.RELEASE]
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
- at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.4.RELEASE.jar:1.4.4.RELEASE]
- at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-1.4.4.RELEASE.jar:1.4.4.RELEASE]
- at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372) [spring-boot-1.4.4.RELEASE.jar:1.4.4.RELEASE]
- at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-1.4.4.RELEASE.jar:1.4.4.RELEASE]
- at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187) [spring-boot-1.4.4.RELEASE.jar:1.4.4.RELEASE]
- at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176) [spring-boot-1.4.4.RELEASE.jar:1.4.4.RELEASE]
- at com.travelsky.srd.tcldp.SrdTcldpApplication.main(SrdTcldpApplication.java:10) [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.4.RELEASE.jar:1.4.4.RELEASE]
- at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) ~[spring-boot-1.4.4.RELEASE.jar:1.4.4.RELEASE]
- at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.4.RELEASE.jar:1.4.4.RELEASE]
- ... 8 common frames omitted
大概意思就是不能啟動(dòng)containerFactory,初始化容器失敗。
異常原因剖析:
經(jīng)過(guò)一系列的debug,發(fā)現(xiàn)是由于使用的CXF多引了一個(gè)包導(dǎo)致的,該包如下:
- <!-- Jetty is needed if you're are not using the CXFServlet -->
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-transports-http-jetty</artifactId>
- <version>${cxf.version}</version>
- </dependency>
引入這個(gè)包后,當(dāng)spring boot啟動(dòng)的時(shí)候,發(fā)現(xiàn)classpath下存在Jetty的jar包,于是推測(cè)我們要使用的容器不是默認(rèn)的tomcat而是jetty,于是使用jetty容器,但是在初始化jetty容器的時(shí)候,卻由于在spring boot中沒有加入jetty starter導(dǎo)致一些jetty容器依賴的某些jar包環(huán)境又不存在,最終導(dǎo)致初始化容器失敗。
異常解決方法:
1、刪除導(dǎo)致spring boot可能認(rèn)為不使用默認(rèn)容器的jar包,上例中可以刪除依賴的jetty的jar包
2、在spring boot中加入spring-boot-starter-jetty,明確我們想使用什么容器,不要讓spring boot引起誤會(huì)和錯(cuò)誤的可能猜測(cè)
通過(guò)上面的幾個(gè)步驟,異常問題解決了,spring boot可以正常啟動(dòng)!
|