登录
首页 >  文章 >  java教程

Spring Boot启动报错“缺少ServletWebServerFactory bean”怎么办?

时间:2024-12-08 22:18:33 427浏览 收藏

从现在开始,努力学习吧!本文《Spring Boot启动报错“缺少ServletWebServerFactory bean”怎么办?》主要讲解了等等相关知识点,我会在golang学习网中持续更新相关的系列文章,欢迎大家关注并积极留言建议。下面就先一起来看一下本篇正文内容吧,希望能帮到你!

Spring Boot启动报错“缺少ServletWebServerFactory bean”怎么办?

spring boot 项目启动报错:“unable to start servletwebserverapplicationcontext due to missing servletwebserverfactory bean”

问题描述

启动 spring boot 项目时,出现以下错误消息:

org.springframework.context.applicationcontextexception: unable to start servletwebserverapplicationcontext due to missing servletwebserverfactory bean.

问题原因

此错误消息表明 spring boot 应用程序无法启动 servlet web 服务器,因为它找不着 servletwebserverfactory bean。

解决方法

解决此问题的步骤如下:

  1. 移除 spring-boot-starter-tomcat 依赖

pom.xml 文件中包含了 spring-boot-starter-tomcat 依赖,这是不必要的,因为 spring-boot-starter-web 已经包含了 tomcat 依赖。因此,把 spring-boot-starter-tomcat 依赖注释掉。

  1. 调整 starter-web 和 starter-security 依赖版本

把 spring-boot-starter-web 和 spring-boot-starter-security 依赖版本设置为相同版本,如 2.1.3.release。

调整后的 pom.xml 依赖部分如下:


    
        org.springframework.boot
        spring-boot-starter-security
        2.1.3.RELEASE
    
    
        org.springframework.boot
        spring-boot-starter-web
        2.1.3.RELEASE
    
    
    
        io.jsonwebtoken
        jjwt-api
        0.11.2
    
    

完成上述调整后,重新启动 spring boot 应用程序,错误应该消失。

好了,本文到此结束,带大家了解了《Spring Boot启动报错“缺少ServletWebServerFactory bean”怎么办?》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多文章知识!

相关阅读
更多>
最新阅读
更多>
课程推荐
更多>