【问题标题】:Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean由于缺少 EmbeddedServletContainerFactory bean,无法启动 EmbeddedWebApplicationContext
【发布时间】:2015-03-19 19:03:43
【问题描述】:

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>

更新1

使用 IntelliJ 构建 jar 工件时也是如此。

更新2

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

Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

UPDATE3

通过添加到 Application.java 使其工作:

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

【问题讨论】:

  • 如何启动应用程序?在我看来,调用 java 时参数 -jar 丢失了。
  • 当我添加 -jar 它显示不同的错误 Unable to access jarfile
  • 听起来你的路径是错误的。您在正确的目录中吗?
  • 这是春靴吗?使用 spring-boot 你不需要那个 maven jar 配置,也不需要你在 application.java 中创建的 bean。
  • 我和工程师 Dollery 有同样的问题。似乎您正试图将其作为 Spring Boot 应用程序运行。如果是这样,那么您需要 spring-boot-maven-plugin 并在您的 jar 中设置所有必需的引用。那么 Spring Boot 呢?

标签: java spring maven jar manifest


【解决方案1】:

好的,所以我为此头疼...我有以下内容:

/**
 * 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 父级作为我的父级,因此我必须在我的插件配置中包含执行部分,如下所示:

      <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

【讨论】:

    猜你喜欢
    • 2016-05-06
    • 1970-01-01
    • 2016-03-05
    • 2014-07-28
    • 1970-01-01
    • 2017-03-30
    • 1970-01-01
    • 2015-07-31
    • 2014-03-14
    相关资源
    最近更新 更多