初学Spring Cloud踩得坑之Caused by: org.springframework.context.ApplicationContextException

2021-05-14 11:27:08 浏览数 (1)

初学Spring Cloud踩得坑之Caused by: org.springframework.context.ApplicationContextException

强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码

初学Spring Cloud踩得坑之

Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

代码语言:javascript复制
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

具体运行错误代码如下:

代码语言:javascript复制
/*
* 提示:该行代码过长,系统自动注释不进行高亮。一键复制会移除系统注释 
* D:javajdk1.8.0_201binjava.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:C:JetBrainsideaIntellij IDEAIntelliJ IDEA 2018.1.4libidea_rt.jar=61907:C:JetBrainsideaIntellij IDEAIntelliJ IDEA 2018.1.4bin" -Dfile.encoding=UTF-8 -classpath D:javajdk1.8.0_201jrelibcharsets.jar;D:javajdk1.8.0_201jrelibdeploy.jar;D:javajdk1.8.0_201jrelibextaccess-bridge-64.jar;D:javajdk1.8.0_201jrelibextcldrdata.jar;D:javajdk1.8.0_201jrelibextdnsns.jar;D:javajdk1.8.0_201jrelibextjaccess.jar;D:javajdk1.8.0_201jrelibextjfxrt.jar;D:javajdk1.8.0_201jrelibextlocaledata.jar;D:javajdk1.8.0_201jrelibextnashorn.jar;D:javajdk1.8.0_201jrelibextsunec.jar;D:javajdk1.8.0_201jrelibextsunjce_provider.jar;D:javajdk1.8.0_201jrelibextsunmscapi.jar;D:javajdk1.8.0_201jrelibextsunpkcs11.jar;D:javajdk1.8.0_201jrelibextzipfs.jar;D:javajdk1.8.0_201jrelibjavaws.jar;D:javajdk1.8.0_201jrelibjce.jar;D:javajdk1.8.0_201jrelibjfr.jar;D:javajdk1.8.0_201jrelibjfxswt.jar;D:javajdk1.8.0_201jrelibjsse.jar;D:javajdk1.8.0_201jrelibmanagement-agent.jar;D:javajdk1.8.0_201jrelibplugin.jar;D:javajdk1.8.0_201jrelibresources.jar;D:javajdk1.8.0_201jrelibrt.jar;C:Userworkspace_idealeyou-shopcloud-demouser-serivcetargetclasses;D:MavenRepositoriesorgspringframeworkbootspring-boot-starter-web2.0.4.RELEASEspring-boot-starter-web-2.0.4.RELEASE.jar;D:MavenRepositoriesorgspringframeworkbootspring-boot-starter2.0.4.RELEASEspring-boot-starter-2.0.4.RELEASE.jar;D:MavenRepositoriesorgspringframeworkbootspring-boot2.0.4.RELEASEspring-boot-2.0.4.RELEASE.jar;D:MavenRepositoriesorgspringframeworkbootspring-boot-autoconfigure2.0.4.RELEASEspring-boot-autoconfigure-2.0.4.RELEASE.jar;D:MavenRepositoriesorgspringframeworkbootspring-boot-starter-logging2.0.4.RELEASEspring-boot-starter-logging-2.0.4.RELEASE.jar;D:MavenRepositorieschqoslogbacklogback-classic1.2.3logback-classic-1.2.3.jar;D:MavenRepositorieschqoslogbacklogback-core1.2.3logback-core-1.2.3.jar;D:MavenRepositoriesorgapachelogginglog4jlog4j-to-slf4j2.10.0log4j-to-slf4j-2.10.0.jar;D:MavenRepositoriesorgapachelogginglog4jlog4j-api2.10.0log4j-api-2.10.0.jar;D:MavenRepositoriesorgslf4jjul-to-slf4j1.7.25jul-to-slf4j-1.7.25.jar;D:MavenRepositoriesjavaxannotationjavax.annotation-api1.3.2javax.annotation-api-1.3.2.jar;D:MavenRepositoriesorgspringframeworkspring-core5.0.8.RELEASEspring-core-5.0.8.RELEASE.jar;D:MavenRepositoriesorgspringframeworkspring-jcl5.0.8.RELEASEspring-jcl-5.0.8.RELEASE.jar;D:MavenRepositoriesorgyamlsnakeyaml1.19snakeyaml-1.19.jar;D:MavenRepositoriesorgspringframeworkbootspring-boot-starter-json2.0.4.RELEASEspring-boot-starter-json-2.0.4.RELEASE.jar;D:MavenRepositoriescomfasterxmljacksoncorejackson-databind2.9.6jackson-databind-2.9.6.jar;D:MavenRepositoriescomfasterxmljacksoncorejackson-annotations2.9.0jackson-annotations-2.9.0.jar;D:MavenRepositoriescomfasterxmljacksoncorejackson-core2.9.6jackson-core-2.9.6.jar;D:MavenRepositoriescomfasterxmljacksondatatypejackson-datatype-jdk82.9.6jackson-datatype-jdk8-2.9.6.jar;D:MavenRepositoriescomfasterxmljacksondatatypejackson-datatype-jsr3102.9.6jackson-datatype-jsr310-2.9.6.jar;D:MavenRepositoriescomfasterxmljacksonmodulejackson-module-parameter-names2.9.6jackson-module-parameter-names-2.9.6.jar;D:MavenRepositoriesorgspringframeworkbootspring-boot-starter-tomcat2.0.4.RELEASEspring-boot-starter-tomcat-2.0.4.RELEASE.jar;D:MavenRepositoriesorgapachetomcatembedtomcat-embed-core8.5.32tomcat-embed-core-8.5.32.jar;D:MavenRepositoriesorgapachetomcatembedtomcat-embed-el8.5.32tomcat-embed-el-8.5.32.jar;D:MavenRepositoriesorgapachetomcatembedtomcat-embed-websocket8.5.32tomcat-embed-websocket-8.5.32.jar;D:MavenRepositoriesorghibernatevalidatorhibernate-validator6.0.11.Finalhibernate-validator-6.0.11.Final.jar;D:MavenRepositoriesjavaxvalidationvalidation-api2.0.1.Finalvalidation-api-2.0.1.Final.jar;D:MavenRepositoriesorgjbossloggingjboss-logging3.3.2.Finaljboss-logging-3.3.2.Final.jar;D:MavenRepositoriescomfasterxmlclassmate1.3.4classmate-1.3.4.jar;D:MavenRepositoriesorgspringframeworkspring-web5.0.8.RELEASEspring-web-5.0.8.RELEASE.jar;D:MavenRepositoriesorgspringframeworkspring-beans5.0.8.RELEASEspring-beans-5.0.8.RELEASE.jar;D:MavenRepositoriesorgspringframeworkspring-webmvc5.0.8.RELEASEspring-webmvc-5.0.8.RELEASE.jar;D:MavenRepositoriesorgspringframeworkspring-aop5.0.8.RELEASEspring-aop-5.0.8.RELEASE.jar;D:MavenRepositoriesorgspringframeworkspring-context5.0.8.RELEASEspring-context-5.0.8.RELEASE.jar;D:MavenRepositoriesorgspringframeworkspring-expression5.0.8.RELEASEspring-expression-5.0.8.RELEASE.jar;D:MavenRepositoriesmysqlmysql-connector-java5.1.32mysql-connector-java-5.1.32.jar;D:MavenRepositoriestkmybatismapper-spring-boot-starter2.0.3mapper-spring-boot-starter-2.0.3.jar;D:MavenRepositoriesorgspringframeworkbootspring-boot-starter-jdbc2.0.4.RELEASEspring-boot-starter-jdbc-2.0.4.RELEASE.jar;D:MavenRepositoriescomzaxxerHikariCP2.7.9HikariCP-2.7.9.jar;D:MavenRepositoriesorgslf4jslf4j-api1.7.25slf4j-api-1.7.25.jar;D:MavenRepositoriesorgspringframeworkspring-jdbc5.0.8.RELEASEspring-jdbc-5.0.8.RELEASE.jar;D:MavenRepositoriesorgspringframeworkspring-tx5.0.8.RELEASEspring-tx-5.0.8.RELEASE.jar;D:MavenRepositoriesorgmybatismybatis3.4.6mybatis-3.4.6.jar;D:MavenRepositoriesorgmybatismybatis-spring1.3.2mybatis-spring-1.3.2.jar;D:MavenRepositoriestkmybatismapper-core1.0.4mapper-core-1.0.4.jar;D:MavenRepositoriesjavaxpersistencepersistence-api1.0persistence-api-1.0.jar;D:MavenRepositoriestkmybatismapper-base1.0.4mapper-base-1.0.4.jar;D:MavenRepositoriestkmybatismapper-weekend1.1.3mapper-weekend-1.1.3.jar;D:MavenRepositoriestkmybatismapper-spring1.0.4mapper-spring-1.0.4.jar;D:MavenRepositoriestkmybatismapper-extra1.0.4mapper-extra-1.0.4.jar;D:MavenRepositoriestkmybatismapper-spring-boot-autoconfigure2.0.3mapper-spring-boot-autoconfigure-2.0.3.jar;D:MavenRepositoriesorgprojectlomboklombok1.16.22lombok-1.16.22.jar cn.itcast.UserApplication
*/

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

2019-09-14 11:15:48.564  INFO 9696 --- [           main] cn.itcast.UserApplication                : Starting UserApplication on DESKTOP-12MVDLN with PID 9696 (C:Userworkspace_idealeyou-shopcloud-demouser-serivcetargetclasses started by 凌枫lqg in C:Userworkspace_idealeyou-shopcloud-demo)
2019-09-14 11:15:48.579  INFO 9696 --- [           main] cn.itcast.UserApplication                : No active profile set, falling back to default profiles: default
2019-09-14 11:15:48.688  INFO 9696 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7a69b07: startup date [Sat Sep 14 11:15:48 CST 2019]; root of context hierarchy
2019-09-14 11:15:49.133  WARN 9696 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
2019-09-14 11:15:49.649 ERROR 9696 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at cn.itcast.UserApplication.main(UserApplication.java:13) [classes/:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:204) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	... 8 common frames omitted


Process finished with exit code 1

出错原因:以前学Spring Boot习惯把启动类的 SpringApplication.run(UserApplication.class,args);中的写成SpringApplication.class,实际是要学成Spring Boot启动类的类名,犯了这么低级的错,找了半天才找出来,改了之后,demo就能照常运行。书写此文,以示警戒,也可以帮助到那些和我一样粗心的人。

0 人点赞