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

Spring Boot技术咨询:spring-boot-starter-parent是否为pom.xml必填父依赖?

Great questions—let's break this down clearly for you:

1. Is spring-boot-starter-parent required as the parent dependency in pom.xml?

No, it's not mandatory, but it’s absolutely the recommended default for most Spring Boot projects.

The spring-boot-starter-parent does a ton of heavy lifting out of the box to simplify your setup:

  • It manages all Spring Boot dependency versions (so you don’t have to specify versions for starters like spring-boot-starter-web)
  • Configures default Maven plugins (like the Spring Boot repackage plugin, resource filtering, and compiler settings)
  • Enforces standard project structure conventions (like recognizing src/main/resources/application.properties as a valid config file)

2. Why did using spring-boot-starter-web as the parent pom cause resource filtering errors?

That makes total sense—spring-boot-starter-web is not designed to be a parent pom.

It’s a starter dependency that pulls in all the libraries you need for a web application (Spring MVC, Tomcat, etc.), but it doesn’t include the plugin configurations or resource handling rules that spring-boot-starter-parent provides. The missing application.properties error you saw happens because without the parent’s resource filtering setup, Maven wasn’t correctly copying your config file into the final build’s classpath.

3. Does a Maven pom.xml always need a parent dependency?

Nope. Maven projects can exist without a parent pom entirely. For Spring Boot specifically, if you can’t use spring-boot-starter-parent (e.g., your organization enforces its own corporate parent pom), you can still use Spring Boot by importing the dependency management bill of materials (BOM) directly.

Here’s how to set that up:

<project>
    <groupId>com.example</groupId>
    <artifactId>my-spring-boot-app</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <!-- Import Spring Boot's dependency management to handle versioning -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>3.2.0</version> <!-- Use your target Spring Boot version -->
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <!-- Add your Spring Boot starters (no version needed thanks to the BOM) -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <!-- Manually configure the Spring Boot Maven plugin (since we're not using the parent) -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>3.2.0</version> <!-- Match the Spring Boot version -->
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Quick Recap

  • Use spring-boot-starter-parent if you can—it simplifies your pom and cuts down on boilerplate
  • Never use starters like spring-boot-starter-web as parent poms; they’re not built for that purpose
  • If you can’t use the official parent, use the spring-boot-dependencies BOM in dependencyManagement plus manual plugin configurations

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 08:18:23