带弹簧靴的多模块项目

alo*_*adi 5 java spring maven

我正在创建一个项目spring-boot.

Spring引导maven结构要求它具有父类定义spring-boot-starter-parent.

我有一种情况,我想将我的应用程序打包为一个多模块结构,我在其中定义包含与地理相关的功能的模块.

像这样的东西,每个模块都有一个罐子包装,

parent Pom
|
|-----------Core module
|
|-----------India Module
|
|----------Africa Module
|
|--------- Europe Module
Run Code Online (Sandbox Code Playgroud)

现在,我可以根据地理位置使用maven配置文件打包我的应用程序,其中在印度配置文件中仅包含和打包核心模块和印度模块.

我如何使用已定义父级的spring boot来实现它spring-boot-starter-parent

alo*_*adi 10

有两种方法可以做到,

  1. 在父pom中使用dependencyManagement,如

     <dependencyManagement>
        <dependencies>
           <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <type>pom</type>
            <version>1.2.3.RELEASE</version>
            <scope>import</scope>
        </dependency>
    </dependencies>
    
    Run Code Online (Sandbox Code Playgroud)

  2. 这就是我这样做的方式.根POM(带有pom包装)有弹簧靴作为父母

    <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>1.2.3.RELEASE</version>
    </parent> 
    
    Run Code Online (Sandbox Code Playgroud)

模块poms将root pom作为父级.POM添加的核心模块依赖于其他模块.它还有'spring-boot-maven-plugin'来制作胖罐.

spring上下文以java -jar Core_xxx.release.jar启动

当然,如果你有组织明智的父母POM,那么第一选择会更合适.