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

Spring Boot应用启动后自动退出,返回exit code 0求助

排查Spring Boot应用启动后自动退出(Exit Code 0)的步骤
  • 检查Web依赖是否存在
    Spring Boot默认如果没有引入Web相关starter,会以普通Java应用模式运行,启动完成后就会自动退出。你需要确保项目依赖中包含spring-boot-starter-web(Servlet栈)或spring-boot-starter-webflux(Reactive栈)。
    Maven项目在pom.xml中添加:

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

    Gradle项目在build.gradle中添加:

    implementation 'org.springframework.boot:spring-boot-starter-web'
    
  • 确认主类注解
    主启动类必须标注@SpringBootApplication注解,这个注解整合了自动配置、组件扫描等核心功能,确保Spring容器正常初始化。示例:

    @SpringBootApplication
    public class DemoApplication {
        public static void main(String[] args) {
            SpringApplication.run(DemoApplication.class, args);
        }
    }
    
  • 查看启动日志
    启动时仔细观察日志:

    • 如果没有出现Tomcat initialized with port(s): 8080 (http)或类似Web容器启动的日志,说明Web环境未加载,大概率是依赖缺失的问题。
    • 如果日志中没有任何异常信息,只是启动完成后直接退出,基本可以确定是没有持续运行的后台线程(Web容器的线程是后台线程,会保持应用运行)。
  • 检查启动参数
    确认IDE的运行配置中没有添加-Dspring.main.exit-on-startup=true参数,这个参数会强制Spring Boot启动后立即退出。

  • 验证Java环境
    确保你使用的是JDK而非JRE,Spring Boot需要JDK的编译能力来正常运行。可以在终端执行java -version查看版本信息,确认输出中包含JDK字样。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 22:18:06