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为例
-
utils::删除多余部分,添加父项目,打包类型为jar
<parent> <groupId>com.code</groupId> <artifactId>walker</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <packaging>jar</packaging>
-
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>
-
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.walker walker-utils 0.0.1-SNAPSHOT com.code.walker walker-api 0.0.1-SNAPSHOT org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test com.alibaba druid-spring-boot-starter org.mybatis.spring.boot mybatis-spring-boot-starter mysql mysql-connector-java runtime com.alibaba.fastjson2 fastjson2 cn.hutool hutool-all com.github.pagehelper pagehelper-spring-boot-starter 1.4.3