项目初始化
商品服务、仓储服务、订单服务、优惠券服务、用户服务
共同点:
- 依赖 spring web、openfeign
- 服务包名:com.ht.mall
- 模块名:
- 优惠券服务:mall-coupon
- 用户服务:mall-member
- 订单服务:mall-order
- 商品服务:mall-product
- 仓储服务:mall-ware
多模块开发
多模块开发中,使用父模块对子模块的管理非常方便。
- 父模块pom中的<_properties>_属性会被子模块继承
- 父模块pom中,在<_dependencyManagement>_中可以进行子模块依赖的版本管理,子模块继承父模块之后,提供作用:锁定版本 + 子模块不用再写 version。
此外,父模块中可以添加依赖作为全局依赖,子模块自动继承。<_dependencyManagement>外的<_dependencies_>_中定义全局依赖。
目录结构:
父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><groupId>com.mall</groupId><artifactId>guli-mall</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging><modules><module>mall-coupon</module><module>mall-member</module><module>mall-order</module><module>mall-product</module><module>mall-ware</module></modules><name>guli-mall</name><description>parent</description><!-- 这里的属性会被子模块继承 --><properties><java.version>1.8</java.version><spring.boot.version>2.4.3</spring.boot.version><spring-cloud.version>2020.0.1</spring-cloud.version></properties><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><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><!-- 这里的依赖会被子模块继承 --><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies></project>
子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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0 <groupId>com.mall</groupId><artifactId>guli-mall</artifactId><version>0.0.1-SNAPSHOT</version>
com.mall mall-product 0.0.1-SNAPSHOT mall-product 商品服务 org.springframework.boot spring-boot-maven-plugin
```
