运行Spring Boot项目时Tomcat未启动且无相关日志求助
问题原因及解决办法
核心问题
你的spring-boot-starter-web依赖设置了<scope>test</scope>,这个作用域意味着该依赖仅在测试阶段生效,主应用运行时不会加载Web模块相关组件(包括嵌入式Tomcat),自然不会启动Tomcat也不会输出相关日志。
修复步骤
- 移除
spring-boot-starter-web依赖中的<scope>test</scope>标签,让它在主应用中生效:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!-- 删除该行:<scope>test</scope> --> </dependency>
- 移除多余的
spring-web依赖,因为spring-boot-starter-web已经包含该依赖,无需单独引入:
<!-- 删除这个依赖节点 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency>
- (可选)给
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
相关产品推荐
相关产品推荐

