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

时间:2015-01-21 09:57:14

标签: java spring maven jar manifest

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

1 个答案:

答案 0 :(得分:4)

好的,所以我正在打扰我......我有以下几点:

-- This is the same as `traverse` for lists and `Either`
traverseListWithEither :: (a -> Either err b) -> [a] -> Either err [b]
traverseListWithEither f [] = Right []
traverseListWithEither f (a:as) =
    case f a of
      Left err -> Left err
      Right b  -> mapEither (b:) (traverseListWithEither f as)

-- This is the same as the `fmap` function for `Either`    
mapEither :: (a -> b) -> Either e a -> Either e b
mapEither f (Left e)  = Left e
mapEither f (Right a) = Right (f a)

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

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

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

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

/**
 * 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/1.4.0.BUILD-SNAPSHOT/maven-plugin/usage.html