关于IDEA springboot项目运行时Unable to start web server问题解决

报错内容:

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

解决方法:

首先,先确保正确创建springboot项目,创建项目是选择spring Initializr,而不是maven项目

项目创建确保后,在你所运行时需要用的的每个类上方添加@EnableAutoConfiguration

记住,是每个类,而不是main方法这一个类,再次尝试运行,就可以了!(提示:有的解决方法告诉说删除依赖的包,那个是完全不可行的,因为版本是建项目时就选好的,和那个没关系)

 

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
问题的原因是缺少ServletWebServerFactory bean,这导致无法启动web服务器。解决方法是添加相应的依赖和配置。 根据引用中的描述,可以看到问题出现在启动Spring Boot项目时。可能的解决方法是在maven的主pom文件中添加spring boot starter tomcat的依赖,如下所示: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency> ``` 但是引用中指出,即使添加了tomcat依赖,仍然需要在pom.xml中排除spring boot starter tomcat的依赖,如下所示: ```xml <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> ``` 另外,引用中提到,如果项目是使用Spring Boot Application直接启动的,而没有使用Tomcat,那么可能需要切换到Tomcat启动,并检查pom.xml中的依赖配置。可以查看pom.xml文件,确保存在类似下面的依赖配置: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!--发布时移除tomcat--> <!--<exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions>--> </dependency> ``` 以上是解决"Unable to start web server"问题的一些常见方法和步骤。希望对您有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [ideaUnable to start web server问题](https://blog.csdn.net/qq_45902560/article/details/124118649)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Spring boot 启动报错:Unable to start web server](https://blog.csdn.net/weixin_42277023/article/details/105989337)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值