在本文中,您将会了解到关于SpringBoot:由于缺少EmbeddedServletContainerFactorybean而无法启动EmbeddedWebApplicationContext的新资
在本文中,您将会了解到关于Spring Boot:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext的新资讯,并给出一些关于ApplicationContextException:由于缺少ServletWebServerFactory bean而无法启动ServletWebServerApplicationContext、ApplicationContextException:由于缺少ServletWebServerFactorybean而无法启动ServletWebServerApplicationContext、IDEA启动spring boot 出现Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCont、java – Spring Boot JAR – 缺少EmbeddedServletContainerFactory的实用技巧。
本文目录一览:- Spring Boot:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext
- ApplicationContextException:由于缺少ServletWebServerFactory bean而无法启动ServletWebServerApplicationContext
- ApplicationContextException:由于缺少ServletWebServerFactorybean而无法启动ServletWebServerApplicationContext
- IDEA启动spring boot 出现Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCont
- java – Spring Boot JAR – 缺少EmbeddedServletContainerFactory
Spring Boot:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext
我收到以下异常:
2019-02-14 16:25:21.614 INFO 9032 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean ''org.springframework.scheduling.annotation.SchedulingConfiguration'' of type [class org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerByCGLIB$$5b48d763] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)2019-02-14 16:25:21.638 INFO 9032 --- [ main] .c.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/work/Spring/SpringTutorial/target/classes/, file:/C:/work/apache-maven-3.0.3/repo/javax/servlet/javax.servlet-api/3.0.1/javax.servlet-api-3.0.1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-starter/1.0.0.RC1/spring-boot-starter-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot/1.0.0.RC1/spring-boot-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-core/4.0.0.RELEASE/spring-core-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-context/4.0.0.RELEASE/spring-context-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-autoconfigure/1.0.0.RC1/spring-boot-autoconfigure-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-starter-logging/1.0.0.RC1/spring-boot-starter-logging-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/slf4j/jcl-over-slf4j/1.7.5/jcl-over-slf4j-1.7.5.jar, file:/C:/work/apache-maven-3.0.3/repo/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar, file:/C:/work/apache-maven-3.0.3/repo/org/slf4j/jul-to-slf4j/1.7.5/jul-to-slf4j-1.7.5.jar, file:/C:/work/apache-maven-3.0.3/repo/org/slf4j/log4j-over-slf4j/1.7.5/log4j-over-slf4j-1.7.5.jar, file:/C:/work/apache-maven-3.0.3/repo/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar, file:/C:/work/apache-maven-3.0.3/repo/ch/qos/logback/logback-core/1.0.13/logback-core-1.0.13.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-starter-web/1.0.0.RC1/spring-boot-starter-web-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-starter-tomcat/1.0.0.RC1/spring-boot-starter-tomcat-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/apache/tomcat/embed/tomcat-embed-core/7.0.47/tomcat-embed-core-7.0.47.jar, file:/C:/work/apache-maven-3.0.3/repo/org/apache/tomcat/embed/tomcat-embed-logging-juli/7.0.47/tomcat-embed-logging-juli-7.0.47.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-web/4.0.0.RELEASE/spring-web-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-aop/4.0.0.RELEASE/spring-aop-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-beans/4.0.0.RELEASE/spring-beans-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-webmvc/4.0.0.RELEASE/spring-webmvc-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-expression/4.0.0.RELEASE/spring-expression-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/com/fasterxml/jackson/core/jackson-databind/2.3.1/jackson-databind-2.3.1.jar, file:/C:/work/apache-maven-3.0.3/repo/com/fasterxml/jackson/core/jackson-annotations/2.3.0/jackson-annotations-2.3.0.jar, file:/C:/work/apache-maven-3.0.3/repo/com/fasterxml/jackson/core/jackson-core/2.3.1/jackson-core-2.3.1.jar, file:/C:/work/apache-maven-3.0.3/repo/commons-lang/commons-lang/2.2/commons-lang-2.2.jar]Exception in thread "main" 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:140) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:124) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:658) at org.springframework.boot.SpringApplication.run(SpringApplication.java:355) at org.springframework.boot.SpringApplication.run(SpringApplication.java:920) at org.springframework.boot.SpringApplication.run(SpringApplication.java:909) at hu.kumite.Application.main(Application.java:17)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:190) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:163) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ... 7 more
应用程序入门类是这样的:
@ComponentScan@EnableAutoConfigurationpublic class Application { public static void main(String[] args) { SpringApplication.run(ScheduledTasks.class, args); }}
如你所见,main方法包含一个注释行。但是我无法运行ScheduledTasks应用程序,如下所示:
@EnableSchedulingpublic class ScheduledTasks { private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); @Scheduled(fixedRate = 5000) public void reportCurrentTime() { System.out.println("The time is now " + dateFormat.format(new Date())); }}
我使用Eclipse并将Application.java的主程序作为应用程序运行。有人可以帮我吗?
答案1
小编典典调度指南不是Web应用程序,因此REST指南中的pom.xml中可能包含一些发霉的东西?如果你严格按照说明进行操作,那么它应该可以工作。你上面发布的代码的另一个潜在问题是,你的@EnableAutoConfiguration
类不在上下文中使用,而只是作为主要方法使用(对于调度指南来说这可能不是问题,但对于其他许多问题而言)。
ApplicationContextException:由于缺少ServletWebServerFactory bean而无法启动ServletWebServerApplicationContext
如何解决ApplicationContextException:由于缺少ServletWebServerFactory bean而无法启动ServletWebServerApplicationContext?
解决方案是:
我明确下面的属性设置为none
在application.yml
文件中。
spring:
main:
web-application-type: none
可能你缺少@SpringBootApplication
Spring Boot入门类。
@SpringBootApplication
public class LoginSecurityAppApplication {
public static void main(String[] args) {
SpringApplication.run(LoginSecurityAppApplication.class, args);
}
}
解决方法
我已经使用Spring Boot编写了Spring Batch应用程序。当我尝试在本地系统上使用命令行和类路径运行该应用程序时,它运行良好。但是,当我尝试在linux服务器上运行它时,出现以下异常
Unable to start web server; nested exception is
org.springframework.context.ApplicationContextException:
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
下面是我的运行方式:
java -cp jarFileName.jar; lib\* -Dlogging.level.org.springframework=DEBUG -Dspring.profiles.active=dev -Dspring.batch.job.names=abcBatchJob com.aa.bb.StartSpringBatch > somelogs.log
ApplicationContextException:由于缺少ServletWebServerFactorybean而无法启动ServletWebServerApplicationContext
我已经使用Spring Boot编写了Spring
Batch应用程序。当我尝试在本地系统上使用命令行和类路径运行该应用程序时,它运行良好。但是,当我尝试在linux服务器上运行它时,出现以下异常
Unable to start web server; nested exception isorg.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
下面是我的运行方式:
java -cp jarFileName.jar; lib\* -Dlogging.level.org.springframework=DEBUG -Dspring.profiles.active=dev -Dspring.batch.job.names=abcBatchJob com.aa.bb.StartSpringBatch > somelogs.log
答案1
小编典典解决方案是:
我none
在application.yml
文件中明确设置了以下属性。
spring: main: web-application-type: none
IDEA启动spring boot 出现Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCont
转载:http://blog.csdn.net/neosmith/article/details/50924681
在 Intellij Idea 中使用maven时,所有 scope 为 provided
的依赖都是不会被加入到 classpath 中的,目前该bug尚未被修复(bug report)。如果你的web应用是部署到容器中的,那么这个bug不会影响使用,因为web应用中provided
的依赖在容器运行时会被提供。如果你做Spring Boot开发,有带provided
的依赖时,直接在IDE中运行项目会导致ClassNotFound
异常。解决方案有二:
- 使用
spring-boot:run
这个 maven goal 运行程序。但这样会失去 Idea 的 debug功能,不推荐。 - 点击IDE右侧的
Maven Projects
, 找到spring-boot:run
,右键选择 debug 运行,如图:
java – Spring Boot JAR – 缺少EmbeddedServletContainerFactory
构建JAR工件以从命令行运行,在启动时抛出错误
org.springframework.context.ApplicationContextException:
无法启动嵌入式容器;
嵌套异常是org.springframework.context.ApplicationContextException:由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext.
问题
>我该如何避免此错误?
>如果我需要声明一个EmbeddedServletContainerFactory,我怎样才能让它的ServletContainer处理我的Controller请求?
尝试解决方案
按错误请求添加了EmbeddedservletContainerFactory.项目现在从JAR开始,但Controller不会像从IntelliJ运行时那样收到请求.
这是我添加EmbeddedServletContainerFactory后Application.class的样子
package org.coursera.diabetes; import com.j256.ormlite.dao.Dao; import com.j256.ormlite.support.ConnectionSource; import diabetes.common.model.*; import org.apache.catalina.connector.Connector; import org.apache.coyote.http11.Http11NioProtocol; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.core.env.Environment; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import java.io.File; import java.io.IOException; import java.sql.sqlException; import java.util.ArrayList; import java.util.List; @SpringBootApplication public class Application { private static final Logger logger = LoggerFactory.getLogger(Application.class); private static final String dbUrl = "jdbc:h2:mem:testdb"; public static void main(String[] args) { SpringApplication.run(Application.class,args); } @Bean @Profile("production") public EmbeddedServletContainerFactory servletContainer(@Value("${keystore.file}") Resource keystoreFile) { TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(); //factory.setPort(8443); String absoluteKeystoreFile = ""; try { absoluteKeystoreFile = keystoreFile.getFile().getAbsolutePath(); logger.info(String.format("******** keystore: %s",absoluteKeystoreFile)); } catch (IOException e) { e.printstacktrace(); } tomcat.addAdditionalTomcatConnectors(createSslConnector(absoluteKeystoreFile)); return tomcat; } private Connector createSslConnector(String absKeystoreFile) { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler(); try { connector.setScheme("https"); connector.setSecure(true); connector.setPort(8443); protocol.setSSLEnabled(true); protocol.setKeystoreFile(absKeystoreFile); protocol.setKeystorePass("changeit"); protocol.setKeyAlias("tomcat"); return connector; } catch (Exception ex) { throw new IllegalStateException("can't access keystore: [" + "keystore" + "] or truststore: [" + "keystore" + "]",ex); } } }
笔记
Spring Boot(Web)应用程序在Intellij IDEA上运行良好,响应https请求,无需在application.properties中执行任何操作:
security.require-ssl=true server.port=8443 server.ssl.key-store=src/main/resources/private/keystore server.ssl.key-store-password=changeit server.ssl.key-password=changeit
要从命令行启动JAR工件,我使用:
java -Dspring.profiles.active=production -Dkeystore.file=file:///$PWD/keystore -jar diabetes-spring.jar
JAR启动时没有错误,但https Web请求(从Intellij工作)只返回Apache / tomcat 404
“请求的资源不可用”.
EDITS
使用-Ddebug运行JAR会输出以下信息(我省略了所有未找到配置文件的DEBUG消息application.properties / application / application-production.properties,这些消息似乎并不相关)
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__,| / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: 2015-11-13 14:16:39.980 INFO 47600 --- [ main] org.coursera.diabetes.Applica tion : Starting Application on Bakers-MacBook-Pro.local with PID 47600 (/User s/baker/coursera-android/MoCCA-15/spring-tests/diabetes_root2/diabetes-spring/out/artifa cts/diabetes_spring_jar/diabetes-spring.jar started by blam in /Users/blam/coursera-and roid/MoCCA-15/spring-tests/diabetes_root2/diabetes-spring/out/artifacts/diabetes_spring _jar) 2015-11-13 14:16:39.983 DEBUG 47600 --- [ main] o.s.boot.SpringApplication : Loading source class org.coursera.diabetes.Application 2015-11-13 14:16:40.011 DEBUG 47600 --- [ main] o.s.b.c.c.ConfigFileApplicati onListener : Activated profiles production 2015-11-13 14:16:40.011 DEBUG 47600 --- [ main] o.s.b.c.c.ConfigFileApplicati onListener : Loaded config file 'file:./config/application.properties' 2015-11-13 14:16:40.020 INFO 47600 --- [ main] ationConfigEmbeddedWebApplica tionContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbe ddedWebApplicationContext@23faf8f2: startup date [Fri Nov 13 14:16:40 WET 2015]; root o f context hierarchy 2015-11-13 14:16:40.022 DEBUG 47600 --- [ main] ationConfigEmbeddedWebApplica tionContext : Bean factory for org.springframework.boot.context.embedded.AnnotationConf igEmbeddedWebApplicationContext@23faf8f2: org.springframework.beans.factory.support.Def aultListablebeanfactory@6cc7b4de: defining beans [org.springframework.context.annotatio n.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.inter nalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalrequired AnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProc essor,application]; root of factory hierarchy 2015-11-13 14:16:40.220 DEBUG 47600 --- [ main] ationConfigEmbeddedWebApplica tionContext : Unable to locate MessageSource with name 'messageSource': using default [ org.springframework.context.support.DelegatingMessageSource@20ce78ec] 2015-11-13 14:16:40.221 DEBUG 47600 --- [ main] ationConfigEmbeddedWebApplica tionContext : Using ApplicationEventMulticaster [org.springframework.context.event.Simp leApplicationEventMulticaster@393671df] 2015-11-13 14:16:40.226 WARN 47600 --- [ main] ationConfigEmbeddedWebApplica tionContext : Exception encountered during context initialization - cancelling refresh attempt org.springframework.context.ApplicationContextException: Unable to start embedded conta iner; nested exception is org.springframework.context.ApplicationContextException: Unab le to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactor y bean. at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRe fresh(EmbeddedWebApplicationContext.java:132) at org.springframework.context.support.AbstractApplicationContext.refresh(Abstr actApplicationContext.java:474) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refr esh(EmbeddedWebApplicationContext.java:117) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:68 9) at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) at org.springframework.boot.SpringApplication.run(SpringApplication.java:969) at org.springframework.boot.SpringApplication.run(SpringApplication.java:958) at org.coursera.diabetes.Application.main(Application.java:40) 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:182) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:155) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:129) ... 7 common frames omitted 2015-11-13 14:16:40.227 INFO 47600 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application Failed to start with classpath: [file:/Users/baker/coursera-android/MoCCA-15/spring-tests/diabetes_root2/diabetes-spring/out/artifacts/diabetes_spring_jar/diabetes-spring.jar] 2015-11-13 14:16:40.228 ERROR 47600 --- [ 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:132) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:117) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:689) at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) at org.springframework.boot.SpringApplication.run(SpringApplication.java:969) at org.springframework.boot.SpringApplication.run(SpringApplication.java:958) at org.coursera.diabetes.Application.main(Application.java:40) 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:182) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:155) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:129) ... 7 common frames omitted
解决方法
将JAR工件更改为此后,我可以构建JAR并从命令行JVM运行它.
对于在HTTPS / SSL端口8443上运行的默认TomcatEmbeddedServletContainerFactory,请指定等于application.properties中所需的java命令行参数.
即
java -jar your-spring.jar --security.require-ssl=true --server.port=8443 --server.ssl.key-store=keystore --server.ssl.key-store-password=changeit --server.ssl.key-password=changeit
今天关于Spring Boot:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext的介绍到此结束,谢谢您的阅读,有关ApplicationContextException:由于缺少ServletWebServerFactory bean而无法启动ServletWebServerApplicationContext、ApplicationContextException:由于缺少ServletWebServerFactorybean而无法启动ServletWebServerApplicationContext、IDEA启动spring boot 出现Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCont、java – Spring Boot JAR – 缺少EmbeddedServletContainerFactory等更多相关知识的信息可以在本站进行查询。
本文标签: