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

IntelliJ IDEA中带子模块的Spring Boot应用无法启动求助

带有子模块的Spring Boot应用启动后立即退出问题

项目结构:

  • parentModule
    • serverModule

serverModule包含@SpringBootApplication主方法与REST控制器,未拆分模块前可正常启动,拆分后启动主方法后立即以Process finished with exit code 0退出。已检查IntelliJ IDEA项目配置与依赖,确认添加了spring-boot-starter-web,但问题仍存在。

父模块POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.boot.test</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>test</name>
    <description>my engine maven</description>
    <modules>
        <module>serve</module>
    </modules>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

子模块POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.boot.test</groupId>
        <artifactId>test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>serve</artifactId>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>3.0.5</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

</project>

解决建议

  • 移除重复依赖:子模块中重复声明了spring-boot-starter-web,保留一个即可(推荐不带版本的,继承父模块版本),重复依赖可能引发类加载冲突或上下文初始化异常。
  • 调整Spring Boot插件位置:父模块是pom打包,无需spring-boot-maven-plugin,将该插件移至子模块的build节点下,只有子模块是可执行的Spring Boot应用。
  • 检查主类包扫描范围:确保@SpringBootApplication的包范围覆盖REST控制器,若控制器在主类的子包外,需手动指定scanBasePackages属性。
  • 清理IDEA缓存并重新导入:执行File -> Invalidate Caches...,重启IDEA后重新导入Maven项目,避免缓存导致的配置不一致。
  • 查看启动日志:将日志级别调至DEBUG,检查启动过程中是否有隐藏异常或上下文初始化失败信息,程序可能因初始化失败但未抛出明显异常而退出。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 07:54:58