您现在的位置是:网站首页 > 代码编程 > JAVA开发JAVA开发

【原】Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean

不忘初心 不忘初心 2021-12-04 围观() 评论() 点赞() JAVA开发

简介:Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean,这就是典型的tomcat依赖没处理好导致的问题。

由于springboot项目内嵌了tomcat,所以一般都会将项目打包成jar包来进行发布,而并非以前的war包,但是公司有一个项目依旧将springboot项目打成war包,然后丢到tomcat容器中运行,这样就需要兼容本地启动调试和线上运行,涉及到tomcat依赖的地方就需要格外注意,一不小心就会导致有一边儿会启动失败。

整理之前的笔记,发现以前还真碰到过这个问题,本地能正常启动,但是发布到线上的时候就报错:Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean,这就是典型的tomcat依赖没处理好导致的问题

.   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '
_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.4.RELEASE)
2020-12-18 09:14:06,263 default [background-preinit] INFO o.h.v.i.u.Version 898 - HV000001: Hibernate Validator 6.1.5.Final
2020-12-18 09:14:06,301 default [main] INFO c.g.l.Application 936 - Starting Application on LAPTOP-9J4HVAON with PID 2568 (D:\workspace_idea\logistics\target\classes started by Administrator in D:\workspace_idea\logistics)
2020-12-18 09:14:06,301 default [main] INFO c.g.l.Application 936 - The following profiles are active: dev
2020-12-18 09:14:07,692 default [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate 2327 - Multiple Spring Data modules found, entering strict repository configuration mode!
2020-12-18 09:14:07,695 default [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate 2330 - Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2020-12-18 09:14:07,760 default [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate 2395 - Finished Spring Data repository scanning in 43ms. Found 0 Redis repository interfaces.
2020-12-18 09:14:08,198 default [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker 2833 - Bean '
redisConfig' of type [com.gude.logistics.config.RedisConfig$$EnhancerBySpringCGLIB$$dfa45a1c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-12-18 09:14:08,221 default [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker 2856 - Bean '
org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@2ffb3aec' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-12-18 09:14:08,226 default [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker 2861 - Bean '
methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-12-18 09:14:08,347 default [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext 2982 - 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.
2020-12-18 09:14:08,357 default [main] INFO o.s.b.a.l.ConditionEvaluationReportLoggingListener 2992 -
Error starting ApplicationContext. To display the conditions report re-run your application with '
debug' enabled.
2020-12-18 09:14:08,368 default [main] ERROR o.s.b.SpringApplication 3003 - 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:161)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.gude.logistics.Application.main(Application.java:12)
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:205)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:177)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:158)
... 9 common frames omitted

因为线上已经使用了tomcat外部容器了,所以在打war包的时候就不在需要tomcat相关的jar包了,否则就会冲突。

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!--注释掉-->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>

搞定,收工!

tomcatspringbootservlet

看完文章,有任何疑问,请加入群聊一起交流!!!

很赞哦! ()

文章评论

  • 请先说点什么
    人参与,条评论

请使用电脑浏览器访问本页面,使用手机浏览器访问本页面会导致下载文件异常!!!

雨落无影

关注上方公众号,回复关键字【下载】获取下载码

用完即删,每次下载需重新获取下载码

若出现下载不了的情况,请及时联系站长进行解决

站点信息

  • 网站程序:spring + freemarker
  • 主题模板:《今夕何夕》
  • 文章统计:篇文章
  • 标签管理标签云
  • 微信公众号:扫描二维码,关注我们