spring boot idea 启动异常

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.



解决方案

在经过多次尝试,几乎要放弃的时候,突然想到一个问题,会不会是因为Intellij集成maven引入jar包时scope设置的问题。

仔细检查pom文件,发现问题可能出现在一下两个地方:

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <version>1.2.3.RELEASE</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-jasper</artifactId>
      <version>7.0.68</version>
      <scope>provided</scope>
    </dependency>

注释掉两个配置中的

<scope>provided</scope>

问题就这么解决了。

总结

这可能是Intellij的一个bug,在使用spring-boot的时候,如果把某个引入的依赖设置为provided,那么在Intellij启动时就会找不到相应的类。因此,此时需要把此项配置给注释掉,但是打包上线的时候并不需要这些依赖,那么在打包的时候就把注释打开,即可。

已经遇到两次相同的问题,谨记!

猜你喜欢

转载自jaycehong.iteye.com/blog/2377822