SpringBoot多模块项目搭建以及搭建基础模板

多模块项目搭建

1.父项目pom文件编辑

    <!--1.父工程 添加pom格式-->
    <packaging>pom</packaging>

    <!--定义子模块-->
    <modules>
        <module>walker-service</module>
        <module>walker-utils</module>
        <module>walker-api</module>
    </modules>
  • maven打包插件:
    <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring.version}</version>
            </plugin>
            <!-- maven打包-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <skipTests>true</skipTests>  <!--默认关掉单元测试 -->
                </configuration>
            </plugin>
        </plugins>
常用依赖与版本:
 依赖版本
 
     1.8
     2.7.12
     1.2.4
     8.0.30
     1.2.17
     2.0.8
     2.9.2
     2.2.2
     5.8.10
 
  
    
        
            org.springframework.boot
            spring-boot-starter
            ${spring.version}
        
        
            org.springframework.boot
            spring-boot-starter-web
            ${spring.version}
        
        
            org.springframework.boot
            spring-boot-starter-test
            ${spring.version}
            test
        
        
        
            com.alibaba
            druid-spring-boot-starter
            ${druid.version}
        
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            ${mybatis.version}
        
        
        
            mysql
            mysql-connector-java
            runtime
            ${mysql-connector-java.version}
        
        
            com.alibaba.fastjson2
            fastjson2
            ${fastjson.version}
        
        
        
            cn.hutool
            hutool-all
            ${hutool.version}
        
     
        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.4.3
        
    
    
     

2.创建子模块

本文以service、utils、api为例

  1. utils::删除多余部分,添加父项目,打包类型为jar

     <parent>
            <groupId>com.code</groupId>
            <artifactId>walker</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
     <packaging>jar</packaging>
    
  2. api:添加父项目,打包类型为jar,添加utils依赖

        <parent>
            <groupId>com.code</groupId>
            <artifactId>walker</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
    <packaging>jar</packaging>
        <dependencies>
            <dependency>
                <groupId>com.code.walker</groupId>
                <artifactId>walker-utils</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
        </dependencies>
    
  3. service:添加父项目,打包为jar,添加utils、api依赖,添加父项目中存在的依赖时可不写依赖version

        <parent>
            <groupId>com.code</groupId>
            <artifactId>walker</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
    
      <packaging>jar</packaging>
    
      <dependency>
                <groupId>com.code.walker</groupId>
                <artifactId>walker-utils</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>com.code.walker</groupId>
                <artifactId>walker-api</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
    
    service其他常用依赖: com.code.walkerwalker-utils0.0.1-SNAPSHOTcom.code.walkerwalker-api0.0.1-SNAPSHOTorg.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-testtest com.alibabadruid-spring-boot-starter org.mybatis.spring.bootmybatis-spring-boot-starter mysqlmysql-connector-javaruntime com.alibaba.fastjson2fastjson2 ​ ​ cn.hutoolhutool-all ​ ​ com.github.pagehelperpagehelper-spring-boot-starter1.4.3
posted @ 2023-06-12 16:13  ProsperousEnding  阅读(329)  评论(0编辑  收藏  举报