2017-07-22 3 views
0

Ich versuche, eine einfache Spring-Boot-Anwendung zu tun. Erhalte eine Ausnahme während der Ausführung als jar.Spring Boot Ausnahme - aufgrund der fehlenden EmbeddedServletContainerFactory Bean

00:48:47.580 [main] ERROR org.springframework.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:137) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) 
    at au.com.itgeeks.spring.cloud.config.SpringCloudConfigurationServer.main(SpringCloudConfigurationServer.java:12) 
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:189) 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) 
    ... 8 common frames omitted 

Alle gut, wenn ich Befehl

mvn spring-boot:run 

aber ich erhalte eine Fehlermeldung während

java -jar target/spring-cloud-config-server-1.0.jar 

meine pom.xml hier eingefügt werden.

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <java.version>1.8</java.version> 
    <spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version> 
    <spring-cloud-starter-config.version>1.2.2.RELEASE</spring-cloud-starter-config.version> 
    <spring-cloud-config-server.version>1.2.2.RELEASE</spring-cloud-config-server.version> 
    <spring-boot-starter-web.version>1.5.1.RELEASE</spring-boot-starter-web.version> 
    <spring-boot-maven-plugin.version>1.5.1.RELEASE</spring-boot-maven-plugin.version> 
    <docker.image.prefix>springio</docker.image.prefix> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework.cloud</groupId> 
     <artifactId>spring-cloud-dependencies</artifactId> 
     <version>${spring-cloud-dependencies.version}</version> 
     <type>pom</type> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.cloud</groupId> 
     <artifactId>spring-cloud-config-server</artifactId> 
     <version>${spring-cloud-starter-config.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-security</artifactId> 
     <version>${spring-boot-starter-web.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
     <version>${spring-boot-starter-web.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <version>${spring-boot-starter-web.version}</version> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.6.1</version> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <version>1.6</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
        <configuration> 
         <transformers> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
           <mainClass>au.com.itgeeks.spring.cloud.config.SpringCloudConfigurationServer</mainClass> 
          </transformer> 
         </transformers> 
         <filters> 
          <filter> 
           <artifact>*:*</artifact> 
           <excludes> 
            <exclude>META-INF/*.SF</exclude> 
            <exclude>META-INF/*.DSA</exclude> 
            <exclude>META-INF/*.RSA</exclude> 
           </excludes> 
          </filter> 
         </filters> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>com.spotify</groupId> 
      <artifactId>docker-maven-plugin</artifactId> 
      <version>0.2.3</version> 
      <configuration> 
       <imageName>${docker.image.prefix}/${project.artifactId}</imageName> 
       <dockerDirectory>src/main/docker</dockerDirectory> 
       <resources> 
        <resource> 
         <targetPath>/</targetPath> 
         <directory>${project.build.directory}</directory> 
         <include>${project.build.finalName}.jar</include> 
        </resource> 
       </resources> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

Bitte beachten Sie - Ich bin mit - Maven-Schatten-Plugin in meinem pom.xml

Antwort ist

Keine Notwendigkeit Gebrauch Schatten Plugin.

  <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <goals> 
         <goal>repackage</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

Oder Sie können als Maven Befehl auch tun. vielen dank an erster kommentar.

+2

Verwenden Sie nicht den 'Maven-Schatten-plugin' ... Die' spring-boot-maven-plugin' sorgt für die Erstellung eines ausführbaren jars. –

+0

danke, Kumpel! Ihre Antwort bringt mich zur Lösung. Bitte lesen Sie die Frage bearbeitet. –

Antwort

0

Verwendung unter Abhängigkeiten:

<dependencies> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-security</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-thymeleaf</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-jpamodelgen</artifactId> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-batch</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.flywaydb</groupId> 
     <artifactId>flyway-core</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.assertj</groupId> 
     <artifactId>assertj-core</artifactId> 
     <version>3.4.1</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
    </dependency> 

</dependencies> 

und Sie brauchen eine Anmerkung auf Hauptklasse verwenden wie:

@Configuration 
@ComponentScan 
@EnableAutoConfiguration 
@SpringBootApplication 
public class TestApplication { 
    public static void main(String[] args) { 
     SpringApplication.run(ScheduledTasks.class, args); 
    } 
} 
Verwandte Themen