idea创建maven多模块Spring Boot项目

时间:2025-03-20 16:34:55

1, 创建父项目

1.1,file - new - project

idea创建maven多模块Spring Boot项目

1.2,选择maven,Create from archetype(有的说不选,有的没说,不过我建父项目的时候没有勾选)

idea创建maven多模块Spring Boot项目

1.3,根据自己实际情况输入相应内容

idea创建maven多模块Spring Boot项目

1.4,根据实际情况放在合适的目录

idea创建maven多模块Spring Boot项目

1.5, finish完成,项目目录以及pom文件如下

idea创建maven多模块Spring Boot项目

1.6,给父项目添加依赖

idea创建maven多模块Spring Boot项目

<?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>com.example</groupId>
<artifactId>manager</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version> <properties>
<java.version>1.8</java.version>
<spring-boot.version>2.0.4.RELEASE</spring-boot.version>
</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> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> </project>

1.7,删除父项目的src,至此父项目完成

2, 建立子项目

2.1,右键项目 - new - module

idea创建maven多模块Spring Boot项目

2.2,选择maven,create from archetype(有的说子项目的这里要勾选,有的没说,我建子项目的时候勾选了)

idea创建maven多模块Spring Boot项目

2.3,根据自己情况填写

idea创建maven多模块Spring Boot项目

2.4直接next

idea创建maven多模块Spring Boot项目

2.5, 子项目刚建好时的项目目录以及pom文件

idea创建maven多模块Spring Boot项目

2.6manager的pom文件中自动增加modules

idea创建maven多模块Spring Boot项目

3,将子项目变为spring boot项目

3.1,在项目的java目录右键 - new package建一项目包

idea创建maven多模块Spring Boot项目

idea创建maven多模块Spring Boot项目

idea创建maven多模块Spring Boot项目

3.2, 在建好的包下右键 - new - Java Class建启动类

idea创建maven多模块Spring Boot项目

idea创建maven多模块Spring Boot项目

3.3, 在启动类中增加注解和启动方法

idea创建maven多模块Spring Boot项目

3.4, 在resource下右键 - new - file增加配置

idea创建maven多模块Spring Boot项目

idea创建maven多模块Spring Boot项目

idea创建maven多模块Spring Boot项目

idea创建maven多模块Spring Boot项目

3.5右键启动类进行启动项目

idea创建maven多模块Spring Boot项目

3.6启动成功

idea创建maven多模块Spring Boot项目

多个子项目同理