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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.wzs</groupId>
<artifactId>order-management-plus</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>order-management-plus</name>
<description>Demo project for Spring Boot</description>
<packaging>pom</packaging>
<properties>
<!-- jdk版本 -->
<java.version>1.8</java.version>
<!-- mybatis版本 -->
<mybatis-vision>2.1.3</mybatis-vision>
<!-- Spring cloud版本 -->
<springcolud-vision>2020.0.3</springcolud-vision>
<!-- Spring boot版本 -->
<springboot-vision>2.5.2</springboot-vision>
<!-- lombok版本 -->
<lombok-vision>1.18.12</lombok-vision>
<!-- eureka版本 -->
<eureka-vision>3.0.3</eureka-vision>
<!-- openfeign版本 -->
<openfeign-vision>3.0.3</openfeign-vision>
<!-- mysql版本 -->
<mysql-vision>8.0.19</mysql-vision>
<!-- slf4j版本 -->
<slf4j-vision>1.7.25</slf4j-vision>
<!-- springfox-swagger版本 -->
<springfox-swagger-vision>2.9.2</springfox-swagger-vision>
<!-- swagger-bootstrap-ui版本 -->
<swagger-bootstrap-vision>1.9.6</swagger-bootstrap-vision>
</properties>
<!-- 子模块配置 -->
<modules>
<module>order-system-eureka</module>
<module>order-system-eureka1</module>
<module>order-service</module>
<module>order-system-common</module>
<module>goods-service</module>
<module>consumer-service</module>
</modules>
<dependencyManagement>
<dependencies>
<!-- Spring cloud -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${springcolud-vision}</version>
<type>pom</type>
<scope>runtime</scope>
</dependency>
<!-- Spring boot web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${springboot-vision}</version>
</dependency>
<!-- Spring boot test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${springboot-vision}</version>
<scope>test</scope>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok-vision}</version>
<scope>provided</scope>
</dependency>
<!-- eureka client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>${eureka-vision}</version>
</dependency>
<!-- eureka server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>${eureka-vision}</version>
</dependency>
<!-- openfeign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>${openfeign-vision}</version>
</dependency>
<!-- jdbc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>${springboot-vision}</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-vision}</version>
</dependency>
<!-- mybatis整合springboot -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis-vision}</version>
</dependency>
<!--日志输出-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-vision}</version>
</dependency>
<!-- springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger-vision}</version>
</dependency>
<!-- springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger-vision}</version>
</dependency>
<!-- swagger-bootstrap-ui -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>${swagger-bootstrap-vision}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
- <modules>标签里是子项目名字,在这里可以先删除;
- <dependencyManagement>标签,在这里面的依赖,子项目在继承父项目时不会直接继承这些依赖,但是子项目在自己的pom里引用该依赖时不用写版本号,父项目更好的管理依赖版本;
2、子项目创建
和父项目一样创建SpringBoot程序
- 在父项目pom中添加<module>,让他认识自己的儿子
- 配置子项目pom
在此以其中一个子项目举例,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>
<parent>
<groupId>com.wzs</groupId>
<artifactId>order-management-plus</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.wzs</groupId>
<artifactId>order-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>order-service</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.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>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- openfeign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!-- jdbc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- mybatis整合springboot -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<!--日志输出-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<!-- springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<!-- swagger-bootstrap-ui -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
</dependency>
<dependency>
<groupId>com.wzs</groupId>
<artifactId>order-system-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
- <parent>换为父项目坐标;
- 注意:是spring-boot-starter-web不是spring-boot-starter(创建SpringBoot程序没选web模块时会出现这种情况,程序跑不起来,错误又不好找)
- 下图坐标为兄弟项目(放置公共类和配置,不用启动),没有可以先删除