一、父模块创建
1、在界面左上角选择File->New->Project后,选择Spring Initializr,默认使用的Java版本是1.8。
除了红色框柱的部分,其他全部删除
二、创建子模块
三、相关配置
1、父pom配置
<?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>
<packaging>pom</packaging>
<modules>
<module>newday</module><!--父模块打包类型必须为pom-->
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com._520xuzai</groupId>
<artifactId>xuzai-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>xuzai-parent</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!-- 在properties中统一控制依赖包的版本,更清晰-->
</properties>
<dependencyManagement> <!--dependencyManagement用于管理依赖版本号-->
<dependencies>
<!-- 删除spring-boot-starter和spring-boot-starter-test,
因为parent中继承的祖先中已经有了,并且一般dependencyManagement管理的依赖都要写版本号 -->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
</dependencies>
</dependencyManagement>
<!--该插件作用是打一个可运行的包,必须要写在需要打包的项目里。这里的父模块不需要打包运行,所以删掉该插件。-->
<!-- <build>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
</project>
2、子pom配置
<?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">
<parent>
<artifactId>xuzai-parent</artifactId>
<groupId>com._520xuzai</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com._520xuzai.newday</groupId>
<artifactId>newday</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<!-- properties可删掉,会继承父模块的-->
<!-- <properties>-->
<!-- <maven.compiler.source>8</maven.compiler.source>-->
<!-- <maven.compiler.target>8</maven.compiler.target>-->
<!-- </properties>-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3、子application
package com._520xuzai.newday;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* \* Created with IntelliJ IDEA.
* \* User: 思源
* \* Date: 2021/1/30
* \* Time: 22:59
* \* To change this template use File | Settings | File Templates.
* \* Description:
* \
*/
@SpringBootApplication
public class NewdayApplication {
public static void main(String[] args) {
SpringApplication.run(NewdayApplication.class, args);
}
}
注意父pom中使用dependencyManagement进行管理