在一个Spring Boot项目中,通常会使用spring-boot-starter-parent作为父级模块,这个模块会提供一些默认的配置和依赖管理。

如果有其他模块也要引用这个spring-boot-starter-parent作为父级模块,可以在这些模块的pom.xml文件中使用<parent>元素来引用父级模块。例如:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.4</version>
    <relativePath/> <!-- 如果父级模块在同一个目录下,可以使用相对路径 -->
</parent>

通过引用父级模块,这些子模块就可以继承父级模块的默认配置和依赖管理。在这些子模块中,可以添加自己需要的其他依赖包,例如:

<dependencies>
    <!-- 其他依赖包 -->
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>my-dependency</artifactId>
        <version>1.0.0</version>
    </dependency>
</dependencies>

这样,子模块就会继承父级模块的默认配置和依赖管理,并且可以添加自己需要的其他依赖包。

Spring Boot 多模块项目依赖管理:如何引用父级模块?

原文地址: https://www.cveoy.top/t/topic/qeHN 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录