java 由于缺少 EmbeddedServletContainerFactory bean,无法启动 EmbeddedWebApplicationContext

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28064199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:57:21  来源:igfitidea点击:

Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

javaspringmavenjarmanifest

提问by J.Olufsen

Maven build succeeded but when I trying to run it fails with:

Maven 构建成功,但是当我尝试运行它时失败:

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

I have in resources/META-INF/MANIFEST.MFwith

我在resources/META-INF/MANIFEST.MF

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

All seems in place. What's wrong?

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

pom.xml

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

更新1

Same story when building jar artifact with IntelliJ.

使用 IntelliJ 构建 jar 工件时的情况相同。

UPDATE2

更新2

OK, I managed to run it but now I have :

好的,我设法运行它,但现在我有:

Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

UPDATE3

更新3

Got it working by adding to Application.java:

通过添加到 Application.java 让它工作:

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

回答by nterry

Ok, So i was beating my head over this... I had the following:

好的,所以我对此感到头疼......我有以下内容:

/**
 * 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);
  }
}

and all my dependencies were correct..

我所有的依赖都是正确的..

After an exhausive search, i found the following:

经过详尽的搜索,我发现了以下内容:

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

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

Since i dont have the spring boot parent as my parent, I had to include the executions section in my plugin configuration like so:

由于我没有 spring boot 父级作为我的父级,因此我必须在我的插件配置中包含执行部分,如下所示:

      <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> 

See the following for additional info:

有关其他信息,请参阅以下内容:

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

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