1.创建父项目
父项目pom.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<!--基本信息-->
<description>Spring boot 多模块项目</description>
<modelVersion>4.0.0</modelVersion>
<name>modules</name>
<!--父类型都为pom类型-->
<packaging>pom</packaging>
<!--项目说明:这里作为聚合工程的父工程-->
<groupId>com.modules</groupId>
<artifactId>modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 继承说明:这里继承SpringBoot提供的父工程 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- 模块说明:这里声明多个子模块 -->
<modules>
<module>module1</module>
<module>module2</module>
</modules>
<!--java版本说明:使用的java版本-->
<properties>
<java.version>1.8</java.version>
</properties>
<!-- 版本说明:这里统一管理依赖的版本号 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.module1</groupId>
<artifactId>module1</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.module2</groupId>
<artifactId>module2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
2.创建子模块
在当前项目下右键,new module
子模块pom.xml
模块一:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--基本信息-->
<groupId>com.module1</groupId>
<artifactId>module1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>module1</name>
<description>模块一</description>
<!-- 继承本项目的父工程 -->
<parent>
<groupId>com.modules</groupId>
<artifactId>modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--模块一依赖模块二,引入依赖-->
<dependency>
<groupId>com.module2</groupId>
<artifactId>module2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
模块二:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--基本信息-->
<groupId>com.module2</groupId>
<artifactId>module2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>module2</name>
<description>模块二</description>
<!-- 继承本项目的父工程 -->
<parent>
<groupId>com.modules</groupId>
<artifactId>modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
</dependencies>
</project>
这样module1就可以调用module2的内容