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

Spring Boot启动服务器后自动关闭问题求助

Spring Boot应用启动后立即关闭的排查与解决方法

嘿,我之前也碰到过一模一样的问题!你的启动类代码看起来完全没问题,问题大概率出在依赖配置上,咱们一步步来排查:

最常见的原因:缺少Web环境依赖

Spring Boot默认如果没有引入web相关的starter,启动后会直接退出(因为没有需要保持运行的容器,比如Tomcat)。你需要在pom.xml里添加spring-boot-starter-web依赖:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

检查parent标签是否配置完整

你贴的pom.xml里<parent&...明显没写完,要确保parent标签是完整的,这是Spring Boot依赖管理的核心:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <!-- 这里用一个稳定版本,比如2.7.14或者3.1.2,根据你的JDK版本选:3.x需要JDK17+,2.x支持JDK8+ -->
    <version>2.7.14</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

查看启动日志确认问题

启动应用时仔细看控制台日志,如果是缺少web依赖,你会看到类似这样的输出(没有Tomcat启动的相关日志):

Started HelloSpringApplication in 1.234 seconds (JVM running for 1.567)
Process finished with exit code 0

如果是其他问题(比如依赖冲突、端口被占用),日志里会有明确的报错信息,顺着报错查就行。

其他可能的小概率原因

  • 有没有在代码里不小心加了System.exit(0)之类的强制退出语句?你的启动类里没有,但如果有其他配置类或者初始化代码,也可以检查下。
  • JDK版本和Spring Boot版本不兼容:比如用Spring Boot 3.x但JDK是11,这会导致启动失败,要对应好版本。

把这些调整完之后,重新启动应用,应该就能看到Tomcat启动的日志,比如Tomcat started on port(s): 8080 (http),这时候再访问localhost:8080就有响应啦!

内容的提问来源于stack exchange,提问作者Airagale

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:52:24