春季启动-由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext

塔库尼塔汗:

春季靴

我试图在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

我使用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'
}

这是配置类:

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");

  }

}

这是我的Application类:

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);
  }


}

而且我也尝试过这些注释。

@ComponentScan
@EnableAutoConfiguration
@Configuration

我刚接触Spring,我不太了解这些注解的功能,我尝试遵循其中的一些注解,但无法解决问题。

Spring Boot:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext

春季启动测试:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext

我尝试使用console(gradle build)构建应用程序,构建成功,但是运行war给我一个错误:无法启动嵌入式Tomcat有人可以帮我吗?

pczeus:

我能够启动并运行您的应用程序。为了使它运行,我所做的唯一更改是在build.gradle文件中注释了几个依赖项。

在下面的依赖关系块中,注释了3行。我之所以删除spring-boot-start-jpa行,是因为我没有配置的dataSource。

但是,如果仅注释掉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')
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Boot由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext

Spring Boot:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext

ApplicationContextException:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext

Springboot 可执行 JAR - 错误:由于缺少 EmbeddedServletContainerFactory bean,无法启动 EmbeddedWebApplicationContext

由于缺少EmbeddedServletContainerFactory bean,Spring应用程序无法启动

ApplicationContextException:由于缺少ServletWebServerFactory bean而无法启动ServletWebServerApplicationContext

Web服务器由于缺少bean而无法启动

春季启动。缺少/ logfile端点

Spring Boot / Tomcat,“由于缺少ServletWebServerFactory bean而无法启动ServletWebServerApplicationContext”

Spring Boot jar由于缺少ServletWebServerFactory bean而无法启动Web服务器

由于缺少Mime JSON而无法启动rake任务

Spring Boot + Apache Camel HTTP组件在启动时崩溃:缺少EmbeddedServletContainerFactory bean

失忆由于音频问题而无法启动

由于权限错误而无法启动jstatd

服务由于登录失败而无法启动

春季启动:找不到bean

春季启动指标statsd无法启动

由于缺少ServletWebServerFactory bean,即使使用@springbootapplication,我也无法启动ServletWebServerApplicationContext。

春季启动公约变量

春季启动性能问题

春季启动基本

春季启动 - 计划配置

FeignClient在春季启动2

春季启动ActiveMQ

MethodArgumentTypeMismatchException春季启动

BeanCurrentlyInCreationException春季启动

EmbeddedServletContainerCustomizer春季启动2.0

在春季启动发送文件

春季启动mongoDB jar