错误:无法启动EmbeddedWebApplicationContext由于缺少EmbeddedServletContainerFactory豆

问题描述:

我创建了一个春天启动的应用及其在Eclipse IDE中工作正常,但是当我试图把它做成与Maven一个独立的罐子,它给我这个错误。错误:无法启动EmbeddedWebApplicationContext由于缺少EmbeddedServletContainerFactory豆

我POM:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>org.springframework</groupId> 
    <artifactId>rcubems</artifactId> 
    <version>0.1.0</version> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.3.2.RELEASE</version> 
    </parent> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
     <!-- tag::actuator[] --> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-actuator</artifactId> 
     </dependency> 
     <!-- end::actuator[] --> 
     <!-- tag::tests[] --> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <!-- end::tests[] --> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-mongodb</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>com.google.guava</groupId> 
      <artifactId>guava</artifactId> 
      <version>19.0</version> 
     </dependency> 
     <dependency> 
      <groupId>joda-time</groupId> 
      <artifactId>joda-time</artifactId> 
      <version>2.9.1</version> 
     </dependency> 

    </dependencies> 

    <properties> 
     <java.version>1.7</java.version> 
     <start-class>com.my.rcms.Application</start-class> 
    </properties> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
      <plugin> 
       <artifactId>maven-failsafe-plugin</artifactId> 
       <executions> 
        <execution> 
         <goals> 
          <goal>integration-test</goal> 
          <goal>verify</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <configuration> 
        <archive> 
         <manifest> 
          <mainClass>com.my.rcms.Application</mainClass> 
         </manifest> 
        </archive> 
        <descriptorRefs> 
         <descriptorRef>jar-with-dependencies</descriptorRef> 
        </descriptorRefs> 
       </configuration> 
       <executions> 
        <execution> 
         <id>make-assembly</id> 
         <phase>package</phase> 
         <goals> 
          <goal>single</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 


    <repositories> 
     <repository> 
      <id>spring-releases</id> 
      <name>Spring Releases</name> 
      <url>https://repo.spring.io/libs-release</url> 
     </repository> 
    </repositories> 
    <pluginRepositories> 
     <pluginRepository> 
      <id>spring-releases</id> 
      <name>Spring Releases</name> 
      <url>https://repo.spring.io/libs-release</url> 
     </pluginRepository> 
    </pluginRepositories> 
</project> 

我的主要类别:

@SpringBootApplication 
public class Application { 

    public static void main(String[] args) { 
     ApplicationContext ctx = SpringApplication.run(Application.class, args); 


    } 

} 

而且我发现,通过以下两条命令

* mvn clean install  
* mvn clean compile assembly:single 

导致与依赖罐子创建的依赖,但不包括正常的jar包。帮助将非常感激。

错误跟踪:

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:133) ~[rcubems-0.1.0-jar-with-dependencies.jar:na] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[rcubems-0.1.0-jar-with-dependencies.jar:na] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[rcubems-0.1.0-jar-with-dependencies.jar:na] 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [rcubems-0.1.0-jar-with-dependencies.jar:na] 
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [rcubems-0.1.0-jar-with-dependencies.jar:na] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [rcubems-0.1.0-jar-with-dependencies.jar:na] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [rcubems-0.1.0-jar-with-dependencies.jar:na] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [rcubems-0.1.0-jar-with-dependencies.jar:na] 
    at com.my.rcms.Application.main(Application.java:12) [rcubems-0.1.0-jar-with-dependencies.jar: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:185) ~[rcubems-0.1.0-jar-with-dependencies.jar:na] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158) ~[rcubems-0.1.0-jar-with-dependencies.jar:na] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[rcubems-0.1.0-jar-with-dependencies.jar:na] 
    ... 8 common frames omitted 
+0

你跑什么,通过弹簧引导Maven的插件或程序集创建的脂肪罐子? –

+1

去除组件插件。春季启动Maven插件应该生成可执行文件。 –

我有同样的问题。我解决它通过添加以下依赖项:

<properties> 
    <jetty.version>9.2.17.v20160517</jetty.version> 
    <maven.compiler.source>1.7</maven.compiler.source> 
    <maven.compiler.target>1.7</maven.compiler.target> 
</properties> 
<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-jetty</artifactId> 
</dependency> 

希望这可以帮助你(虽然你很久以前有这个问题)。