简体   繁体   English

Spring boot -- 由于缺少 EmbeddedServletContainerFactory bean 无法启动 EmbeddedWebApplicationContext

[英]Spring boot -- Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

Spring Boot弹簧靴

I was trying to running my spring Boot application in intelliJ but getting an Error:我试图在 intelliJ 中运行我的 spring Boot 应用程序,但出现错误:

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

2016-01-26 23:09:30.883  INFO 3960 --- [           main] com.example.he.ExampleApplication         : Starting ExampleApplication on user with PID 3960 (F:\WORK\Work_Project\Example_Application-master\Example_Application-master\build\classes\main started by user in F:\WORK\Work_Project\Example_Application-master\Example_Application-master)
2016-01-26 23:09:30.892  INFO 3960 --- [           main] com.example.he.ExampleApplication         : No active profile set, falling back to default profiles: default
2016-01-26 23:09:31.042  INFO 3960 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@73d4cc9e: startup date [Tue Jan 26 23:09:31 IST 2016]; root of context hierarchy
2016-01-26 23:09:31.242  WARN 3960 --- [           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-01-26 23:09:31.453 ERROR 3960 --- [           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-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1124) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1113) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at com.example.he.ExampleApplication.main(ExampleApplication.java:15) [main/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) [idea_rt.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-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    ... 13 common frames omitted

2016-01-26 23:09:31.456  INFO 3960 --- 

Process finished with exit code 1

Iam using Gradle.This is my build.gradle file:我正在使用 Gradle。这是我的build.gradle文件:

buildscript {
    ext {
        springBootVersion = '1.3.1.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'

war {
    baseName = 'Example-Application'
    version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.apache.tomcat.embed:tomcat-embed-jasper:8.0.30')
        compile('javax.servlet:servlet-api:2.5')
    compile('javax.servlet:jstl:1.2')
    runtime('mysql:mysql-connector-java')
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testCompile('org.springframework.boot:spring-boot-starter-test')
}


eclipse {
    classpath {
         containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
         containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.9'
}

This is the configuration class:这是配置类:

package com.example.he.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/city").setViewName("city");
    registry.addViewController("/").setViewName("city");
    registry.addViewController("/userAdd").setViewName("user");
    registry.addViewController("/created").setViewName("created");
    registry.addViewController("/createblog").setViewName("blog");
    registry.addViewController("/login").setViewName("login");
    registry.addViewController("/home").setViewName("home");

  }

}

And this is my Application class:这是我的应用程序类:

package com.example.he;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
public class ExampleApplication extends SpringBootServletInitializer{

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


  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(ExampleApplication.class);
  }


}

and also i have tried these annotations as well.而且我也尝试过这些注释。

@ComponentScan
@EnableAutoConfiguration
@Configuration

I am new to spring and i don't really understand what these annotations do.I tried following some of these but couldn't fix the issue.我是 spring 的新手,我不太明白这些注释的作用。我尝试遵循其中的一些注释,但无法解决问题。

Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean Spring Boot:由于缺少 EmbeddedServletContainerFactory bean 无法启动 EmbeddedWebApplicationContext

Spring Boot Testing: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean Spring Boot 测试:由于缺少 EmbeddedServletContainerFactory bean 无法启动 EmbeddedWebApplicationContext

I tried building the application using console(gradle build), build is successful but running the war gives me an error: Unable to start embedded Tomcat .我尝试使用控制台(gradle build)构建应用程序,构建成功但运行战争给我一个错误:无法启动嵌入式 Tomcat Could someone please help me ?有人可以帮我吗?

I also have this error and it only happens with Intellij.我也有这个错误,它只发生在 Intellij 上。 Finally I got it working by commenting out this:最后我通过注释掉了它:

<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-tomcat</artifactId>
     <scope>provided</scope>
</dependency>

It did take me lots of time figuring this out.我确实花了很多时间来弄清楚这一点。 Hope this helps those who encountering the similar error.希望这可以帮助那些遇到类似错误的人。

I was able to get your application up and running.我能够启动并运行您的应用程序。 The only change I made to get it running was to comment out a couple of your dependencies in your build.gradle file.我为让它运行所做的唯一更改是在 build.gradle 文件中注释掉几个依赖项。

In the dependencies block below, 3 lines are commented out.在下面的依赖项块中,注释掉了 3 行。 The spring-boot-start-jpa line I commented out only because I did not have a configured dataSource.我注释掉的 spring-boot-start-jpa 行只是因为我没有配置数据源。

However, if you only comment out the servlet-api and jstl dependencies, your app should start without issue, it did for me.但是,如果您只注释掉 servlet-api 和 jstl 依赖项,那么您的应用程序应该可以正常启动,这对我来说确实如此。

dependencies {
    //compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.apache.tomcat.embed:tomcat-embed-jasper:8.0.30')
    //compile('javax.servlet:servlet-api:2.5')
    //compile('javax.servlet:jstl:1.2')
    runtime('mysql:mysql-connector-java')
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

In my case I missed to add this in pom.xml就我而言,我错过了在pom.xml 中添加它

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

Adding annotation on main boot application class worked for me.在主引导应用程序类上添加注释对我有用。 @EnableAutoConfiguration public class ExampleApplication{..... @EnableAutoConfiguration 公共类 ExampleApplication{.....

Atleast in my case, this was a Intellij specific issue, as the Boot-app worked just fine when running Eclipse/VSCode.至少在我的情况下,这是一个 Intellij 特定问题,因为启动应用程序在运行 Eclipse/VSCode 时工作得很好。

I started getting this issue post the new Intellij update 2020 CE.在新的 Intellij 更新 2020 CE 发布后,我开始遇到此问题。 This was apparently solved after selecting dependencies with provided scope option.在使用提供的范围选项选择依赖项后,这显然已解决。

在此处输入图片说明

Cleaning the C:\\Users\\Lenovo\\.m2\\repository and then reimporting all maven dependencies worked for me.清理C:\\Users\\Lenovo\\.m2\\repository然后重新导入所有对我有用的 maven 依赖项。 I also deleted all overriding dependencies in my pom.xml.我还删除了 pom.xml 中的所有覆盖依赖项。

Adding the annotation @EnableAutoConfiguration solved my issue.添加注释@EnableAutoConfiguration解决了我的问题。 But my only doubt is @SpringBootApplication should internally add @EnableAutoconfiguration .但我唯一的疑问是@SpringBootApplication应该在内部添加@EnableAutoconfiguration This is as per spring web site https://spring.io/guides/gs/rest-service/这是根据 spring 网站https://spring.io/guides/gs/rest-service/

Not sure what to believe...It took 8 hours to find out this.不知道该相信什么...花了 8 个小时才发现这一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot:由于缺少 EmbeddedServletContainerFactory bean 无法启动 EmbeddedWebApplicationContext - Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean 由于缺少 EmbeddedServletContainerFactory bean,Spring Boot 无法启动 EmbeddedWebApplicationContext - Spring Boot Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean 由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext - Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean 带Web套接字的Spring Boot微服务:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext - Spring Boot Microservice w/ Web Sockets: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean 错误:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext - Error : Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean Springboot可执行JAR-错误:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext - Springboot Executable JAR - Error: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean Spring Boot异常-由于缺少EmbeddedServletContainerFactory bean - Spring boot exception - due to missing EmbeddedServletContainerFactory bean 由于缺少EmbeddedServletContainerFactory bean,Spring Application无法启动 - Spring Application doesn't start due to missing EmbeddedServletContainerFactory bean Jetty 9 + Spring 引导 - 由于缺少 ServletWebServerFactory bean,无法启动 ServletWebServerApplicationContext - Jetty 9 + Spring Boot - Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean spring-boot web 应用程序启动失败:由于缺少 ServletWebServerFactory bean,无法启动 ServletWebServerApplicationContext - spring-boot web app fails to start : Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM