A-A+
Missing EmbeddedServletContainerFactory问题解决记录
最近有个项目需要用Spring Boot,为了偷懒就直接拷贝了一下已有的架子。本地开发和测试的时候,运行的流畅无比。结果上线服务器的时候,就直接异常崩溃了。
报错:
Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
详细的错误见下图:

开始以为在POM文件中丢了相关的配置,仔细的和原工程比对之后,发现并没有任何不同,主要的配置如下:
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
<version>1.5.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
<version>1.5.4.RELEASE</version>
</dependency>
搜索了一下解决办法:
首先,解决办法是增加XXX包的,这种办法就不考虑了,我并没有缺失任何包,另外一个相同的项目跑的很流畅。
然后,是增加@EnableAutoConfiguration注解,我觉得也不是这个问题,因为在IDEA中是可以运行的。
最后,是增加一段代码,如下:
@Bean
public EmbeddedServletContainerFactory servletContainer() {
return new JettyEmbeddedServletContainerFactory();
}
增加了上面这段代码后,出现了新的报错:
org/eclipse/jetty/webapp/WebAppContext : Unsupported major.minor version 52.
这个报错就很明显了,肯定是因为JDK版本问题。开发机上是JDK1.8,而服务器上是JDK1.7。所以修改了一下POM文件的配置:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
配置修改完毕后,重新打包部署,然后可以正常运行。如果您也遇到了相同的问题,可以按此尝试一下。
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.4.RELEASE)
