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

电玩女神 2023-10-09 20:14 122阅读 0赞

目录

    • 一、场景
    • 二、报错信息
    • 三、原因
    • 四、解决

一、场景

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

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

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


二、报错信息

  1. 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.
  2. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157)
  3. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
  4. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
  5. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
  6. at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
  7. at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
  8. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
  9. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
  10. at com.xxx.RobotManagerSvr.main(RobotManagerSvr.java:32)
  11. Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
  12. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:206)
  13. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180)
  14. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154)
  15. ... 8 common frames omitted

三、原因

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

原依赖导入配置

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-tomcat</artifactId>
  4. <!--是provided导致-->
  5. <scope>provided</scope>
  6. </dependency>

四、解决

调整后依赖导入配置

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

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

发表评论

表情:
评论列表 (有 0 条评论,122人围观)

还没有评论,来说两句吧...

相关阅读