You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行Spring Boot项目时Tomcat未启动且无相关日志求助

问题原因及解决办法

核心问题

你的spring-boot-starter-web依赖设置了<scope>test</scope>,这个作用域意味着该依赖仅在测试阶段生效,主应用运行时不会加载Web模块相关组件(包括嵌入式Tomcat),自然不会启动Tomcat也不会输出相关日志。

修复步骤

  1. 移除spring-boot-starter-web依赖中的<scope>test</scope>标签,让它在主应用中生效:
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- 删除该行:<scope>test</scope> -->
</dependency>
  1. 移除多余的spring-web依赖,因为spring-boot-starter-web已经包含该依赖,无需单独引入:
<!-- 删除这个依赖节点 -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
</dependency>
  1. (可选)给spring-boot-starter-test添加<scope>test</scope>,测试依赖仅需在测试阶段生效:
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

验证

修改后重新运行应用,你会看到Tomcat启动的日志,类似:

Tomcat initialized with port 8080 (http)
Starting service [Tomcat]
Starting Servlet engine: [Apache Tomcat/10.1.24]

内容的提问来源于stack exchange,提问作者Lý Duy Bách

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 21:04:57