Error missing EmbeddedServletContainerFactory bean

0

Excuse me, I'm new to this. I am trying to execute a .jar generated in eclipse using java -jar spring-boot-hello-world.jar and this is the error that generates me:

  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _' | \ \ \ \
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                        

2016-07-20 19:06:28.007  INFO 1087 --- [           main] io.github.web.DemoApplication            : Starting DemoApplication on sergios-MacBook-Pro.local with PID 1087 (/Users/sergio/Desktop/spring-boot-hello-world.jar started by sergio in /Users/sergio/Desktop)
2016-07-20 19:06:28.010  INFO 1087 --- [           main] io.github.web.DemoApplication            : No active profile set, falling back to default profiles: default
2016-07-20 19:06:28.081  INFO 1087 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1d8d30f7: startup date [Wed Jul 20 19:06:28 CEST 2016]; root of context hierarchy
2016-07-20 19:06:28.395  WARN 1087 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
2016-07-20 19:06:28.402 ERROR 1087 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-hello-world.jar:na]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-boot-hello-world.jar:na]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-hello-world.jar:na]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-hello-world.jar:na]
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-hello-world.jar:na]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-hello-world.jar:na]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-hello-world.jar:na]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-hello-world.jar:na]
    at io.github.web.DemoApplication.main(DemoApplication.java:10) [spring-boot-hello-world.jar:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:185) ~[spring-boot-hello-world.jar:na]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158) ~[spring-boot-hello-world.jar:na]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-hello-world.jar:na]
    ... 8 common frames omitted

2016-07-20 19:06:28.405  INFO 1087 --- [           main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/Users/sergio/Desktop/spring-boot-hello-world.jar]

This is my GreetingController.java class:

package io.github.web.spring.mvc_hello_world;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class GreetingController {
   @RequestMapping("/greeting")
   public ModelAndView greeting() {
      return new ModelAndView("greeting_template").addObject("name", "World");
   }
}

This is my class SpringMvcHelloWorldApp.java:

package io.github.web.spring.mvc_hello_world;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@SpringBootApplication
public class SpringMvcHelloWorldApp extends WebMvcConfigurerAdapter {

    public static void main(String[] args) {
        SpringApplication.run(SpringMvcHelloWorldApp.class, args);
    }
}

This is my pom.xml file

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>io.github.web</groupId>
  <artifactId>ThymeLeafDemo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>ThymeLeafDemo</name>
  <url>http://maven.apache.org</url>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.7.RELEASE</version>
</parent>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
  <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Can anyone help me?

Greetings.

    
asked by Sesiño Perezma 20.07.2016 в 19:09
source

1 answer

0

I have it fixed, I was not packaging the application with Maven.

To package an application with Maven you have to go to the root directory of the project and execute this command:

mvn package
    
answered by 22.01.2018 в 18:00