Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

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;
        }
like image 379
J.Olufsen Avatar asked Jan 21 '15 09:01

J.Olufsen


1 Answers

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

like image 186
Nicholas Terry Avatar answered Sep 18 '22 16:09

Nicholas Terry