Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

只谈情不闲聊 提交于 2019-12-04 17:40:25

问题


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

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

I have in 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

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

Got it working by adding to Application.java:

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

回答1:


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



来源:https://stackoverflow.com/questions/28064199/unable-to-start-embeddedwebapplicationcontext-due-to-missing-embeddedservletcont

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!