如何在idea中新建一个父工程,然后在父工程下新建多个微服务模块?
一、新建父工程
1.1 新建New Project

1.2 删掉多余文件
创建好后,把多余的文件删掉,变成这样
1.3 修改pom文件
- 添加<packaging>pom</packaging>
- 添加parent属性
修改后的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>cachedemo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>cachedemo</name>
<description>cachedemo</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.13</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
二、新建新模块
2.1 新建New Module
这样

或者这样

2.2 选择parent

创建后结构变成这样

2.3 修改目录文件
修改后

2.4 修改 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.example</groupId>
<artifactId>cachedemo</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>testdemo</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
reload maven project 过后,文件的图标应该变成这样

新建新模块完成
三、导入新模块
3.1 将导入的模块根目录移动到 父工程的根目录下,这时候idea目录里多了个没有图标的目录
3.2 导入新模块

已经导入成功了

可能报红,慢慢解决,修改parent啥的
四、添加java模块

