Spring引导 - 由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext [英] Spring boot -- Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean
本文介绍了Spring引导 - 由于缺少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与PID 3960(F:\ WORK \ Work_Project\Example_Application-master\Example_Application-master\build\classes\main)由用户在F:\\\\\\\\\\\\\\\\\\\\\\ Example_Application-master)
2016-01-26 23:09:30.892信息3960 --- [main] com.example.he.ExampleApplication:没有活动配置集,回退到默认配置文件:default
2016年1月26日23:09:31.042 INFO 3960 --- [主要] ationConfigEmbeddedWebApplicationContext:刷新org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@73d4cc9e:启动日期[星期二年01月26 23点09分31秒IST 2016];上下文结构
的根2016年1月26日23:09:31.242 WARN 3960 --- [主] ationConfigEmbeddedWebApplicationContext:异常情况下初始化过程中遇到 - 取消刷新尝试:org.springframework.context.ApplicationContextException:无法启动嵌入式容器;嵌套异常是org.springframework.context.ApplicationContextException:由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext。
2016-01-26 23:09:31.453错误3960 --- [main] osboot.SpringApplication:应用程序启动失败
org.springframework.context.ApplicationContextException:无法启动嵌入容器;嵌套异常是org.springframework.context.ApplicationContextException:由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext。在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)
〜[弹簧引导1.3.1.RELEASE.jar:1.3.1.RELEASE]
。在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)〜[弹簧上下文4.2.4.RELEASE.jar:4.2.4.RELEASE]
。在org.springframework.boot.context .embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)〜[弹簧引导1.3.1.RELEASE.jar:1.3.1.RELEASE]在org.springframework.boot.SpringApplication.refresh
(SpringApplication。 java:764)[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
在org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357)[spring-boot-1.3 .1.RELEASE.jar:1.3.1.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:305)[spring-boot-1.3.1.RELEASE.jar:1.3.1 .RELEASE]
在org.springframework.boot.SpringApplication.run(Spring Application.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(本机方法)〜[NA:1.8.0_25]在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
〜[NA:1.8.0_25]在太阳
。 reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[NA:1.8.0_25]
。在java.lang.reflect.Method.invoke(Method.java:483)〜[NA:1.8.0_25] $在com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)b $ b [idea_rt.jar:NA]:org.springframework.context.ApplicationContextException:无法启动EmbeddedWebApplicationContext
。通过致由于缺少EmbeddedServletContainerFactory bean。在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:185)
〜[弹簧引导1.3.1.RELEASE.jar:1.3.1.RELEASE]
。在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158)〜[弹簧引导1.3.1.RELEASE.jar:1.3.1.RELEASE]
。在org.springframework.boot .context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130)〜[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
...省略13个常见帧
2016-01-26 23:09:31.456信息3960 ---
程序完成退出代码1
Iam使用Gradle.This是我的 build.gradle 文件:
buildscript {
ext {
springBootVersion ='1.3.1.RELEASE'
}
知识库{
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
存储库{
mavenCentral()
}
依赖关系{
compile('org.springframework.boot:spring- ('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-boot-start-data-jpa')
compile
compile('org.apache.tomcat.embed:tomcat-embed-jasper:8.0.30')
compile('javax.servlet:servlet-api:2.5')
编译('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'
}
}
任务包装器(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
公共类MvcConfig扩展WebMvcConfigurerAdapter {
@覆盖
公共无效addViewControllers(ViewControllerRegistry注册表){
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);
}
}
这是我的应用程序类:
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
公共类ExampleApplication延伸SpringBootServletInitializer {
公共静态无效的主要(字串[] args)抛出异常{
SpringApplication.run(ExampleApplication .class,args);
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application){
return application.sources(ExampleApplication.class);
}
}
还有我
@ComponentScan
@EnableAutoConfiguration
@Configuration
我对春天很陌生,并且我不太了解这些注释的作用。我尝试了其中的一些方法, t解决了这个问题。
查看全文