簡體   English   中英

由於缺少EmbeddedServletContainerFactory bean,無法啟動EmbeddedWebApplicationContext

[英]Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

Maven構建成功,但是當我嘗試運行它失敗時:

Error: Could not find or load main class app.jar

我有resources/META-INF/MANIFEST.MF

Manifest-Version: 1.0
Main-Class: go.Application

一切似乎都到位了。 怎么了?

的pom.xml

<build>
        <plugins>
             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <archive>
                        <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>

            </plugin>

        </plugins>
    </build>

UPDATE1

使用IntelliJ構建jar工件時也是如此。

UPDATE2

好的,我設法運行它,但現在我有:

Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

UPDATE3

通過添加到Application.java來實現它:

@Bean
        public EmbeddedServletContainerFactory servletContainer() {
            TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
            return factory;
        }

好的,所以我正在打擾我......我有以下幾點:

/**
 * Main class.
 */
@SpringBootApplication
public class Application {

  /**
   * Main entry point for the application.
   *
   * @param args The args to pass in
   */
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}

我所有的依賴都是正確的..

經過詳盡的搜索,我發現了以下內容:

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#getting-started-first-application-executable-jar

因為我沒有將spring boot parent作為我的父級,所以我必須在我的插件配置中包含執行部分,如下所示:

      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <mainClass>your.Application.fqdn.here</mainClass>
          <layout>ZIP</layout>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin> 

有關其他信息,請參閱以下內容

http://docs.spring.io/spring-boot/docs/1.4.0.BUILD-SNAPSHOT/maven-plugin/usage.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM