Java Spring应用程序没有';由于缺少EmbeddedServletContainerFactorybean,无法启动

Java Spring应用程序没有';由于缺少EmbeddedServletContainerFactorybean,无法启动,java,spring,maven,intellij-idea,spring-boot,Java,Spring,Maven,Intellij Idea,Spring Boot,我试图在heroku上部署一个应用程序,但遇到了几个问题。该应用程序正在我的IDE(Intellij)中运行,但当我尝试使用“heroku local-f Procfile.windows”运行它时,出现以下错误: 11:30:03 PM web.1 | 2016-05-24 23:30:03.491 WARN 10368 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountere

我试图在heroku上部署一个应用程序,但遇到了几个问题。该应用程序正在我的IDE(Intellij)中运行,但当我尝试使用“heroku local-f Procfile.windows”运行它时,出现以下错误:

11:30:03 PM web.1 |  2016-05-24 23:30:03.491  WARN 10368 --- [           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.
11:30:03 PM web.1 |  2016-05-24 23:30:03.505 ERROR 10368 --- [           main] o.s.boot.SpringApplication               : Application startup failed
11:30:03 PM web.1 |  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.
11:30:03 PM web.1 |     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[CinemaMagic-1.0-SNAPSHOT-jar-with-dependencies.jar:1.0-SNAPSHOT]
11:30:03 PM web.1 |     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[CinemaMagic-1.0-SNAPSHOT-jar-with-dependencies.jar:1.0-SNAPSHOT]
11:30:03 PM web.1 |     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[CinemaMagic-1.0-SNAPSHOT-jar-with-dependencies.jar:1.0-SNAPSHOT]
11:30:03 PM web.1 |     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [CinemaMagic-1.0-SNAPSHOT-jar-with-dependencies.jar:1.0-SNAPSHOT]
11:30:03 PM web.1 |     at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [CinemaMagic-1.0-SNAPSHOT-jar-with-dependencies.jar:1.0-SNAPSHOT]
11:30:03 PM web.1 |     at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [CinemaMagic-1.0-SNAPSHOT-jar-with-dependencies.jar:1.0-SNAPSHOT]
11:30:03 PM web.1 |     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [CinemaMagic-1.0-SNAPSHOT-jar-with-dependencies.jar:1.0-SNAPSHOT]
11:30:03 PM web.1 |     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [CinemaMagic-1.0-SNAPSHOT-jar-with-dependencies.jar:1.0-SNAPSHOT]
11:30:03 PM web.1 |     at cinemagic.main.App.main(App.java:27) [CinemaMagic-1.0-SNAPSHOT-jar-with-dependencies.jar:1.0-SNAPSHOT]
11:30:03 PM web.1 |  Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
11:30:03 PM web.1 |     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:185) ~[CinemaMagic-1.0-SNAPSHOT-jar-with-dependencies.jar:1.0-SNAPSHOT]
11:30:03 PM web.1 |     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158) ~[CinemaMagic-1.0-SNAPSHOT-jar-with-dependencies.jar:1.0-SNAPSHOT]
11:30:03 PM web.1 |     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[CinemaMagic-1.0-SNAPSHOT-jar-with-dependencies.jar:1.0-SNAPSHOT]
11:30:03 PM web.1 |     ... 8 common frames omitted
procfile如下所示: web:java-jar-target\cinemagic-1.0-SNAPSHOT-jar-with-dependencies.jar

Pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>CinemaMagic</groupId>
<artifactId>CinemaMagic</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>cinemagic.main.App</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.3.RELEASE</version>
</parent>

<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.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>4.0.4.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.2.5.RELEASE</version>
    </dependency>

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

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>3.2.3.RELEASE</version>
    </dependency>

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

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>4.0.4.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.2.5.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>4.0.4.RELEASE</version>
    </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.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.9.4.RELEASE</version>
    </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>
    </dependency>

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

</dependencies>

首先,初学者使用框架,而不是反对/围绕框架工作。你的依赖关系一团糟,你没有使用正确的插件

首先删除所有插件并替换为
springbootmaven
插件。(有关此信息,另请参见)

现在重建您的jar并启动它


注意:主要问题是您没有使用Spring Boot maven插件,而是自己尝试使用

转到C:\Users\username.m2\repository\org\springframework\boot

删除spring boot自动配置并重新构建maven


它会工作的,它会再次生成。

这就解决了它!非常感谢。从现在开始,我会记住从一个好的maven构建开始:)。
@SpringBootApplication
@ComponentScan("cinemagic")
@EnableJpaRepositories("cinemagic.repositories")
@EntityScan(basePackages = { "cinemagic.model"})
@EnableScheduling
public class App extends WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/").setCachePeriod(0);
    super.addResourceHandlers(registry);
}

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

}
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<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>
@SpringBootApplication
@EnableScheduling
public class App 

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

}