由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext [英] Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

查看:3624
本文介绍了由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

我在 resources / META-INF / MANIFEST.MF with

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

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

All seems in place. What's wrong?

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工件时的情况相同。

Same story when building jar artifact with IntelliJ.

UPDATE2

确定,我设法运行它,但现在我有:

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

Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

UPDATE3

通过添加到Application.java来实现它:

Got it working by adding to Application.java:

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


推荐答案

好的,所以我在殴打我对此有所了解......我有以下内容:

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

因为我没有弹簧启动父亲作为我的父,我必须在我的插件配置中包含执行部分,如下所示:

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

      <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

这篇关于由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆