需求案例:搭建一个电商平台项目,该平台包括用户服务、订单服务、通用工具模块等。
项目架构:
服务依赖:
<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.0modelVersion>
<groupId>per.mjngroupId>
<artifactId>maven-micro-shopartifactId>
<version>1.0.1version>
<packaging>pompackaging>
<modules>
<module>user-servicemodule>
<module>order-servicemodule>
<module>common-servicemodule>
modules>
<properties>
<spring.version>6.0.6spring.version>
<jackson.version>2.15.0jackson.version>
<shiro.version>1.10.1shiro.version>
<io.version>2.11.0io.version>
<maven.compiler.source>17maven.compiler.source>
<maven.compiler.target>17maven.compiler.target>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-contextartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-databindartifactId>
<version>${jackson.version}version>
dependency>
<dependency>
<groupId>org.apache.shirogroupId>
<artifactId>shiro-coreartifactId>
<version>${shiro.version}version>
dependency>
<dependency>
<groupId>commons-iogroupId>
<artifactId>commons-ioartifactId>
<version>${io.version}version>
dependency>
<dependency>
<groupId>per.mjngroupId>
<artifactId>common-serviceartifactId>
<version>1.0.1version>
dependency>
dependencies>
dependencyManagement>
project>
<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.0modelVersion>
<parent>
<groupId>per.mjngroupId>
<artifactId>maven-micro-shopartifactId>
<version>1.0.1version>
parent>
<artifactId>common-serviceartifactId>
<dependencies>
<dependency>
<groupId>commons-iogroupId>
<artifactId>commons-ioartifactId>
dependency>
dependencies>
project>
使用maven中的构建命令install,将这个项目放到maven本地仓库,以供其他两个模块(user-service 和 order-service)使用。

显示出BUILD SUCCESS表示构建成功。

<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.0modelVersion>
<parent>
<groupId>per.mjngroupId>
<artifactId>maven-micro-shopartifactId>
<version>1.0.1version>
parent>
<artifactId>user-serviceartifactId>
<packaging>warpackaging>
<dependencies>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-contextartifactId>
dependency>
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-databindartifactId>
dependency>
<dependency>
<groupId>per.mjngroupId>
<artifactId>common-serviceartifactId>
dependency>
dependencies>
project>
<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.0modelVersion>
<parent>
<groupId>per.mjngroupId>
<artifactId>maven-micro-shopartifactId>
<version>1.0.1version>
parent>
<artifactId>order-serviceartifactId>
<packaging>warpackaging>
<dependencies>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-contextartifactId>
dependency>
<dependency>
<groupId>org.apache.shirogroupId>
<artifactId>shiro-coreartifactId>
dependency>
<dependency>
<groupId>per.mjngroupId>
<artifactId>common-serviceartifactId>
dependency>
dependencies>
project>