1.创建父工程,用于聚合其他微服务模块
1.1创建父项目
说明:我们先创建一个父项目,该父项目会去管理多个微服务模块(module),如下:
(1)File-New-Project-Maven,选择如下:
(2)输入项目名称等信息,然后next
(3)选择Maven,然后Finish
1.2项目设置
(1)File-Settings-Editor-File Encodings,将编码改为UTF-8,点击Apply
(2)Settings-Build,Execution,Deployment-Compiler-Java Compiler,将项目的编译版本改为8,点击OK
(3)删除父项目的src目录
(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> |
|
<groupId>com.li.springcloud</groupId> |
|
<artifactId>E-Commerce-Center</artifactId> |
|
<version>1.0-SNAPSHOT</version> |
|
<!--将packaging的值改为pom,表明是一个父工程,聚合管理其他模块--> |
|
<packaging>pom</packaging> |
|
<name>E-Commerce-Center</name> |
|
<!-- FIXME change it to the project's website --> |
|
<url>http://www.example.com</url> |
|
<!--统一配置各个依赖版本--> |
|
<properties> |
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
|
<maven.compiler.source>1.8</maven.compiler.source> |
|
<maven.compiler.target>1.8</maven.compiler.target> |
|
<junit.version>4.12</junit.version> |
|
<!--使用最新版本的 log4j , 防止安全漏洞--> |
|
<log4j.version>2.17.2</log4j.version> |
|
<lombok.version>1.18.20</lombok.version> |
|
<mysql.version>5.1.47</mysql.version> |
|
<druid.version>1.1.17</druid.version> |
|
<mybatis.spring.boot.version>2.2.0</mybatis.spring.boot.version> |
|
</properties> |
|
<!--dependencyManagement 作用:子模块继承后,锁定版本,子模块不用再写version--> |
|
<dependencyManagement> |
|
<dependencies> |
|
<!--配置Spring-Boot的依赖--> |
|
<dependency> |
|
<groupId>org.springframework.boot</groupId> |
|
<artifactId>spring-boot-dependencies</artifactId> |
|
<version>2.2.2.RELEASE</version> |
|
<!--1.type:pom 和 scope import配合使用 |
|
2.表示父项目的子模块,在引入springboot相关依赖时,锁定版本为2.2.2.RELEASE |
|
3.通过pom+import 解决 maven 单继承机制--> |
|
<type>pom</type> |
|
<scope>import</scope> |
|
</dependency> |
|
<!--配置SpringCloud(注意和spring-boot版本对应关系)--> |
|
<dependency> |
|
<groupId>org.springframework.cloud</groupId> |
|
<artifactId>spring-cloud-dependencies</artifactId> |
|
<version>Hoxton.SR1</version> |
|
<type>pom</type> |
|
<scope>import</scope> |
|
</dependency> |
|
<!--SpringCloud Alibaba--> |
|
<dependency> |
|
<groupId>com.alibaba.cloud</groupId> |
|
<artifactId>spring-cloud-alibaba-dependencies</artifactId> |
|
<version>2.1.0.RELEASE</version> |
|
<type>pom</type> |
|
<scope>import</scope> |
|
</dependency> |
|
<!--mysql--> |
|
<dependency> |
|
<groupId>mysql</groupId> |
|
<artifactId>mysql-connector-java</artifactId> |
|
<version>${mysql.version}</version> |
|
</dependency> |
|
<!--druid数据源--> |
|
<dependency> |
|
<groupId>com.alibaba</groupId> |
|
<artifactId>druid</artifactId> |
|
<version>${druid.version}</version> |
|
</dependency> |
|
<!--SpringBoot 整合 mybatis 的 starter--> |
|
<dependency> |
|
<groupId>org.mybatis.spring.boot</groupId> |
|
<artifactId>mybatis-spring-boot-starter</artifactId> |
|
<version>${mybatis.spring.boot.version}</version> |
|
</dependency> |
|
<!--log4j--> |
|
<dependency> |
|
<groupId>org.apache.logging.log4j</groupI |