解决程序启动报错org.springframework.context.ApplicationContextException: Unable to start web server问题

 更新时间:2024年11月16日 10:50:31   作者:天黑请​闭眼  
文章描述了一个Spring Boot项目在不同环境下启动时出现差异的问题,通过分析报错信息,发现是由于导入`spring-boot-starter-tomcat`依赖时定义的scope导致的配置问题,调整依赖导入配置后,解决了启动错误

一、场景

1、该项目在Linux和本机电脑上启动都正常

2、在另一台电脑上启动就报错

3、代码都是同一份,没有差别

二、报错信息

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:157)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
    at com.xxx.RobotManagerSvr.main(RobotManagerSvr.java:32)
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:206)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154)
    ... 8 common frames omitted

三、原因

导入spring-boot-starter-tomcat依赖时定义的scope导致

原依赖导入配置

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-tomcat</artifactId>
    <!--是provided导致-->
	<scope>provided</scope>
</dependency>

四、解决

调整后依赖导入配置

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-tomcat</artifactId>
    <!--测试时先注释该配置-->
	<!--<scope>provided</scope>-->
</dependency>

注:

  • 本机就算是provided也能正常启动
  • 另一台电脑上就不行
  • 应该是运行环境上的差异

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • 详解Java中Object 类的使用

    详解Java中Object 类的使用

    Java的Object 类是所有类的父类,也就是说 Java 的所有类都继承了 Object,本文主要来和大家讲讲Object 类的使用,感兴趣的可以了解一下
    2023-05-05
  • Java中的CountDownLatch简单理解

    Java中的CountDownLatch简单理解

    这篇文章主要介绍了Java中的CountDownLatch简单理解,CountDownLatch是一个同步工具类,用来携调多个线程之间的同步,它是是使用一个计数器进行实现的,计数器初始值为线程数量,需要的朋友可以参考下
    2024-01-01
  • Spring boot整合Springfox生成restful的在线api文档

    Spring boot整合Springfox生成restful的在线api文档

    这篇文章主要为大家介绍了Spring boot整合Springfox生成restful在线api文档,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步
    2022-03-03
  • 使用spring jpa 如何给外键赋值

    使用spring jpa 如何给外键赋值

    这篇文章主要介绍了使用spring jpa 如何给外键赋值,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-06-06
  • Java中RabbitMQ消息队列的交换机详解

    Java中RabbitMQ消息队列的交换机详解

    这篇文章主要介绍了Java中的RabbitMQ交换机详解,消息队列是指利用高效可靠的消息传递机制进行与平台无关的数据交流,并基于数据通信来进行分布式系统的集成,是在消息的传输过程中保存消息的容器,需要的朋友可以参考下
    2023-07-07
  • SpringBoot docker项目部署实战

    SpringBoot docker项目部署实战

    本文主要介绍了SpringBoot docker项目部署实战,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-08-08
  • SpringBoot导出Excel表格到指定路径的代码详解

    SpringBoot导出Excel表格到指定路径的代码详解

    Spring Boot导出Excel通常涉及到使用第三方库如Apache POI或者XlsxWriter等,它们能帮助你在Spring应用中生成并下载Excel文件,那么SpringBoot如何导出Excel表格到指定路径,本文将给大家详细的介绍一下
    2024-07-07
  • 【Redis缓存机制】详解Java连接Redis_Jedis_事务

    【Redis缓存机制】详解Java连接Redis_Jedis_事务

    这篇文章主要介绍了【Redis缓存机制】详解Java连接Redis_Jedis_事务,详细的介绍了Jedis事务和实例,有兴趣的可以了解一下。
    2016-12-12
  • SpringMvc切换Json转换工具的操作代码

    SpringMvc切换Json转换工具的操作代码

    SpringBoot切换使用goolge的Gson作为SpringMvc的Json转换工具,本文给大家讲解SpringMvc切换Json转换工具的操作代码,感兴趣的朋友一起看看吧
    2024-02-02
  • Java判断字符串回文的代码实例

    Java判断字符串回文的代码实例

    在本篇文章里小编给各位整理的是一篇关于Java判断字符串回文的代码实例内容,需要的朋友们可以跟着学习参考下。
    2020-02-02

最新评论