# 新增服务模块

在实际项目架构设计和开发过程中,会根据项目业务模块的划分来对服务进行拆分,因此需要新建业务模块,如 商品服务订单服务积分服务支付服务 等等一系列可能的子服务,下面在微服务框架的基础上以 订单服务 为例详细的阐述如何在Maven多模块下新建子模块的操作流程;

首先需要了解目前的微服务架构,本框架中所有的业务子服务全部放在 javaweb-service 模块下,在此模块中新建的任何服务都是他的子模块,我们以订单服务模块 javaweb-service-order 为例来新建Maven子模块;

  • 第一步:选择新建子模块

mixureSecure

  • 第二步:选择Maven模块新建

mixureSecure

  • 第三步:设置模块名

mixureSecure

  • 第四步:自动创建模块

设置模块名确定后会自动生成 订单服务 模块,会自动生成 pom.xml 文件,如下图所示:

mixureSecure

特别说明

在子服务模块创建的同时,会自动在 javaweb-service 模块的根 pom.xml 中自动加入子模块依赖,如下图所示:

mixureSecure

  • 第五步:自定义子模块的依赖

在生成的服务模块 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">
    <parent>
        <artifactId>javaweb-service</artifactId>
        <groupId>com.javaweb</groupId>
        <version>1.0.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>javaweb-service-order</artifactId>
    <packaging>jar</packaging>
    <name>javaweb-service-order</name>
    <description>微服务订单模块</description>


    <!-- 依赖声明 -->
    <dependencies>

        <!-- 安全认证 -->
        <dependency>
            <groupId>com.javaweb</groupId>
            <artifactId>javaweb-common-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- SpringCloud Netflix Hystrix -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>

        <!-- MySql驱动 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!--mybatis-plus 代码自动生成 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.2.0</version>
        </dependency>
        <!-- freemarker模板引擎依赖 -->
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.28</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>com.javaweb</groupId>
            <artifactId>javaweb-common-redis</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93