货币交易项目-架构设计和模块搭建 (二)-依赖关系的解决-03

一、项目内部依赖关系

项目的内部依赖关系表明的是:在coin-exchange该项目内部,我的那个模块需要依赖那个模块。

file

1.1在所有service 里面添加自己项目api的依赖

涉及的项目包含:

  • coin-admin
  • coin-member
  • coin-finance
  • coin-chan
  • coin-statistics
  • match-engine
  • exchange-engine
    在这些项目的service 里面均需要添加api的依赖。
    对于远程调用,我们暂时先不做依赖的管理

coin-admin/admin-service 的pom.xml文件添加 api的依赖

    <dependencies>
        <dependency>
            <groupId>com.quantsmart</groupId>
            <artifactId>admin-api</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>

1.2 打包依赖后的项目

在IDEA找到我们 coin-exchange 该父项目,点击install 即可打包所有的项目。
file

打包日志记录:

[INFO] coin-exchange ...................................... SUCCESS [  0.707 s]
[INFO] coin-iass .......................................... SUCCESS [  0.017 s]
[INFO] gateway-server ..................................... SUCCESS [  2.279 s]
[INFO] authorization-server ............................... SUCCESS [  0.115 s]
[INFO] coin-common ........................................ SUCCESS [  0.155 s]
[INFO] coin-member ........................................ SUCCESS [  0.029 s]
[INFO] member-api ......................................... SUCCESS [  0.147 s]
[INFO] member-service ..................................... SUCCESS [  0.149 s]
[INFO] coin-finance ....................................... SUCCESS [  0.032 s]
[INFO] finance-api ........................................ SUCCESS [  0.101 s]
[INFO] finance-service .................................... SUCCESS [  0.107 s]
[INFO] coin-chan .......................................... SUCCESS [  0.016 s]
[INFO] chan-api ........................................... SUCCESS [  0.103 s]
[INFO] chan-service ....................................... SUCCESS [  0.128 s]
[INFO] coin-task .......................................... SUCCESS [  0.018 s]
[INFO] task-api ........................................... SUCCESS [  0.082 s]
[INFO] task-service ....................................... SUCCESS [  0.084 s]
[INFO] coin-statistics .................................... SUCCESS [  0.018 s]
[INFO] statistics-api ..................................... SUCCESS [  0.077 s]
[INFO] statistics-service ................................. SUCCESS [  0.074 s]
[INFO] match-engine ....................................... SUCCESS [  0.014 s]
[INFO] match-api .......................................... SUCCESS [  0.075 s]
[INFO] match-service ...................................... SUCCESS [  0.068 s]
[INFO] exchange-engine .................................... SUCCESS [  0.013 s]
[INFO] exchange-api ....................................... SUCCESS [  0.098 s]
[INFO] exchange-service ................................... SUCCESS [  0.072 s]
[INFO] coin-admin ......................................... SUCCESS [  0.014 s]
[INFO] admin-api .......................................... SUCCESS [  0.055 s]
[INFO] admin-service ...................................... SUCCESS [  0.062 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.348 s
[INFO] Finished at: 2021-03-20T13:00:16+08:00
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "dev" could not be activated because it does not exist.

二、项目的外部依赖

file

2.1 通过parent引入springboot

在coin-exchange项目里面,添加如下:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

2.2 通过依赖管理导入springcloud

2.2.1定义版本号

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR3</spring-cloud.version>
    </properties>

2.2.2 依赖管理

<dependencyManagement>
    <dependencies>
        <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>

2.3 通过依赖管理导入spring-cloud-alibaba

2.3.1定义版本号

<properties>
<java.version>1.8</java.version>
<com-alibaba-cloud.version>2.2.0.RELEASE</com-alibaba-cloud.version>
</properties>

2.3.2 依赖管理

<dependencyManagement>
    <dependencies>
     <dependency>
<groupId>com.alibaba.cloud</groupId>
      <artifactId>spring-cloud-alibaba-dependencies</artifactId>
      <version>${com-alibaba-cloud.version}</version>
      <type>pom</type>
      <scope>import</scope>
     </dependency>
</dependencies>
</dependencyManagement>

2.4 其他依赖的导入

其他依赖我们均采用依赖管理的方式来导入
注意:其他依赖具体的作用,我们在使用到时,再给大家说明。

2.4.1 版本号的定义

<properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR3</spring-cloud.version>
        <com-alibaba-cloud.version>2.2.0.RELEASE</com-alibaba-cloud.version>
        <mybatis-plus-boot-stater.version>3.3.2</mybatis-plus-boot-stater.version>
        <druid-boot-stater.version>1.1.23</druid-boot-stater.version>
        <redisson-spring-boot-starter.version>3.13.3</redisson-spring-boot-starter.version>
        <jetcache-starter-redis.version>2.6.0</jetcache-starter-redis.version>
        <disruptor.version>3.4.2</disruptor.version>
        <org.mapstruct.version>1.4.0.Beta3</org.mapstruct.version>
        <commons-beanutils.version>1.9.4</commons-beanutils.version>
        <swagger-annotations.version>1.5.20</swagger-annotations.version>
        <googleauth.version>1.1.5</googleauth.version>
        <net.sf.supercsv.version>2.4.0</net.sf.supercsv.version>
        <springside-utils.version>5.0.0-RC1</springside-utils.version>
        <aliyun-sdk-oss.version>3.1.0</aliyun-sdk-oss.version>
        <aliyun-java-sdk-core.version>4.0.3</aliyun-java-sdk-core.version>
        <aliyun-java-sdk-dm.version>3.3.1</aliyun-java-sdk-dm.version>
        <joda-time.version>2.10</joda-time.version>
        <okhttp.version>3.11.0</okhttp.version>
        <okio.version>1.15.0</okio.version>
    </properties>

2.4.2 依赖管理

<dependencyManagement>
      <dependencies>
          <dependency>
              <groupId>org.springframework.cloud</groupId>
              <artifactId>spring-cloud-dependencies</artifactId>
              <version>${spring-cloud.version}</version>
              <type>pom</type>
              <scope>import</scope>
          </dependency>
          <dependency>
              <groupId>com.alibaba.cloud</groupId>
              <artifactId>spring-cloud-alibaba-dependencies</artifactId>
              <version>${com-alibaba-cloud.version}</version>
              <type>pom</type>
              <scope>import</scope>
          </dependency>
          <dependency>
              <groupId>io.swagger</groupId>
              <artifactId>swagger-annotations</artifactId>
              <version>${swagger-annotations.version}</version>
          </dependency>
          <dependency>
              <groupId>com.baomidou</groupId>
              <artifactId>mybatis-plus-boot-starter</artifactId>
              <version>${mybatis-plus-boot-stater.version}</version>
          </dependency>
          <dependency>
              <groupId>com.baomidou</groupId>
              <artifactId>mybatis-plus-annotation</artifactId>
              <version>${mybatis-plus-boot-stater.version}</version>
          </dependency>
          <!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter -->
          <dependency>
              <groupId>com.alibaba</groupId>
              <artifactId>druid-spring-boot-starter</artifactId>
              <version>${druid-boot-stater.version}</version>
          </dependency>

          <dependency>
              <groupId>commons-beanutils</groupId>
              <artifactId>commons-beanutils</artifactId>
              <version>${commons-beanutils.version}</version>
          </dependency>
          <!-- https://mvnrepository.com/artifact/org.redisson/redisson-spring-boot-starter -->
          <dependency>
              <groupId>org.redisson</groupId>
              <artifactId>redisson-spring-boot-starter</artifactId>
              <version>${redisson-spring-boot-starter.version}</version>
          </dependency>

          <!-- https://mvnrepository.com/artifact/com.alicp.jetcache/jetcache-starter-redis -->
          <dependency>
              <groupId>com.alicp.jetcache</groupId>
              <artifactId>jetcache-starter-redis</artifactId>
              <version>${jetcache-starter-redis.version}</version>
          </dependency>
          <!-- https://mvnrepository.com/artifact/com.lmax/disruptor -->
          <dependency>
              <groupId>com.lmax</groupId>
              <artifactId>disruptor</artifactId>
              <version>${disruptor.version}</version>
          </dependency>
          <dependency>
              <groupId>io.springfox</groupId>
              <artifactId>springfox-swagger2</artifactId>
              <version>${swagger2.version}</version>
          </dependency>
          <dependency>
              <groupId>io.springfox</groupId>
              <artifactId>springfox-swagger-ui</artifactId>
              <version>${swagger2.version}</version>
          </dependency>

          <!--mapStruct依赖-->
          <dependency>
              <groupId>org.mapstruct</groupId>
              <artifactId>mapstruct-jdk8</artifactId>
              <version>${org.mapstruct.version}</version>
          </dependency>
          <dependency>
              <groupId>org.mapstruct</groupId>
              <artifactId>mapstruct-processor</artifactId>
              <version>${org.mapstruct.version}</version>
              <scope>provided</scope>
          </dependency>

          <dependency>
              <groupId>net.sf.supercsv</groupId>
              <artifactId>super-csv</artifactId>
              <version>${net.sf.supercsv.version}</version>
          </dependency>

          <dependency>
              <groupId>io.springside</groupId>
              <artifactId>springside-utils</artifactId>
              <version>${springside-utils.version}</version>
          </dependency>

          <dependency>
              <groupId>org.flywaydb</groupId>
              <artifactId>flyway-core</artifactId>
              <version>${flyway.version}</version>
          </dependency>
          <dependency>
              <groupId>joda-time</groupId>
              <artifactId>joda-time</artifactId>
              <version>${joda-time.version}</version>
          </dependency>
          <dependency>
              <groupId>com.squareup.okhttp3</groupId>
              <artifactId>okhttp</artifactId>
              <version>${okhttp.version}</version>
          </dependency>
          <dependency>
              <groupId>com.squareup.okio</groupId>
              <artifactId>okio</artifactId>
              <version>${okio.version}</version>
          </dependency>
          <dependency>
              <groupId>com.aliyun.oss</groupId>
              <artifactId>aliyun-sdk-oss</artifactId>
              <version>${aliyun-sdk-oss.version}</version>
          </dependency>
          <dependency>
              <groupId>com.aliyun</groupId>
              <artifactId>aliyun-java-sdk-core</artifactId>
              <version>${aliyun-java-sdk-core.version}</version>
          </dependency>
          <dependency>
              <groupId>com.aliyun</groupId>
              <artifactId>aliyun-java-sdk-dm</artifactId>
              <version>${aliyun-java-sdk-dm.version}</version>
          </dependency>
      </dependencies>
    </dependencyManagement>

完整的 coin-exchange/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.quantsmart</groupId>
    <artifactId>coin-exchange</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>
    <modules>
        <module>coin-iass</module>
        <module>coin-common</module>
        <module>coin-member</module>
        <module>coin-finance</module>
        <module>coin-chan</module>
        <module>coin-task</module>
        <module>coin-statistics</module>
        <module>match-engine</module>
        <module>exchange-engine</module>
        <module>coin-admin</module>
    </modules>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR3</spring-cloud.version>
        <com-alibaba-cloud.version>2.2.0.RELEASE</com-alibaba-cloud.version>
        <mybatis-plus-boot-stater.version>3.3.2</mybatis-plus-boot-stater.version>
        <druid-boot-stater.version>1.1.23</druid-boot-stater.version>
        <redisson-spring-boot-starter.version>3.13.3</redisson-spring-boot-starter.version>
        <jetcache-starter-redis.version>2.6.0</jetcache-starter-redis.version>
        <disruptor.version>3.4.2</disruptor.version>
        <org.mapstruct.version>1.4.0.Beta3</org.mapstruct.version>
        <commons-beanutils.version>1.9.4</commons-beanutils.version>
        <swagger-annotations.version>1.5.20</swagger-annotations.version>
        <googleauth.version>1.1.5</googleauth.version>
        <net.sf.supercsv.version>2.4.0</net.sf.supercsv.version>
        <springside-utils.version>5.0.0-RC1</springside-utils.version>
        <aliyun-sdk-oss.version>3.1.0</aliyun-sdk-oss.version>
        <aliyun-java-sdk-core.version>4.0.3</aliyun-java-sdk-core.version>
        <aliyun-java-sdk-dm.version>3.3.1</aliyun-java-sdk-dm.version>
        <joda-time.version>2.10</joda-time.version>
        <okhttp.version>3.11.0</okhttp.version>
        <okio.version>1.15.0</okio.version>
    </properties>

    <dependencyManagement>
      <dependencies>
          <dependency>
              <groupId>org.springframework.cloud</groupId>
              <artifactId>spring-cloud-dependencies</artifactId>
              <version>${spring-cloud.version}</version>
              <type>pom</type>
              <scope>import</scope>
          </dependency>
          <dependency>
              <groupId>com.alibaba.cloud</groupId>
              <artifactId>spring-cloud-alibaba-dependencies</artifactId>
              <version>${com-alibaba-cloud.version}</version>
              <type>pom</type>
              <scope>import</scope>
          </dependency>
          <dependency>
              <groupId>io.swagger</groupId>
              <artifactId>swagger-annotations</artifactId>
              <version>${swagger-annotations.version}</version>
          </dependency>
          <dependency>
              <groupId>com.baomidou</groupId>
              <artifactId>mybatis-plus-boot-starter</artifactId>
              <version>${mybatis-plus-boot-stater.version}</version>
          </dependency>
          <dependency>
              <groupId>com.baomidou</groupId>
              <artifactId>mybatis-plus-annotation</artifactId>
              <version>${mybatis-plus-boot-stater.version}</version>
          </dependency>
          <!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter -->
          <dependency>
              <groupId>com.alibaba</groupId>
              <artifactId>druid-spring-boot-starter</artifactId>
              <version>${druid-boot-stater.version}</version>
          </dependency>

          <dependency>
              <groupId>commons-beanutils</groupId>
              <artifactId>commons-beanutils</artifactId>
              <version>${commons-beanutils.version}</version>
          </dependency>
          <!-- https://mvnrepository.com/artifact/org.redisson/redisson-spring-boot-starter -->
          <dependency>
              <groupId>org.redisson</groupId>
              <artifactId>redisson-spring-boot-starter</artifactId>
              <version>${redisson-spring-boot-starter.version}</version>
          </dependency>

          <!-- https://mvnrepository.com/artifact/com.alicp.jetcache/jetcache-starter-redis -->
          <dependency>
              <groupId>com.alicp.jetcache</groupId>
              <artifactId>jetcache-starter-redis</artifactId>
              <version>${jetcache-starter-redis.version}</version>
          </dependency>
          <!-- https://mvnrepository.com/artifact/com.lmax/disruptor -->
          <dependency>
              <groupId>com.lmax</groupId>
              <artifactId>disruptor</artifactId>
              <version>${disruptor.version}</version>
          </dependency>
          <dependency>
              <groupId>io.springfox</groupId>
              <artifactId>springfox-swagger2</artifactId>
              <version>${swagger2.version}</version>
          </dependency>
          <dependency>
              <groupId>io.springfox</groupId>
              <artifactId>springfox-swagger-ui</artifactId>
              <version>${swagger2.version}</version>
          </dependency>

          <!--mapStruct依赖-->
          <dependency>
              <groupId>org.mapstruct</groupId>
              <artifactId>mapstruct-jdk8</artifactId>
              <version>${org.mapstruct.version}</version>
          </dependency>
          <dependency>
              <groupId>org.mapstruct</groupId>
              <artifactId>mapstruct-processor</artifactId>
              <version>${org.mapstruct.version}</version>
              <scope>provided</scope>
          </dependency>

          <dependency>
              <groupId>net.sf.supercsv</groupId>
              <artifactId>super-csv</artifactId>
              <version>${net.sf.supercsv.version}</version>
          </dependency>

          <dependency>
              <groupId>io.springside</groupId>
              <artifactId>springside-utils</artifactId>
              <version>${springside-utils.version}</version>
          </dependency>

          <dependency>
              <groupId>org.flywaydb</groupId>
              <artifactId>flyway-core</artifactId>
              <version>${flyway.version}</version>
          </dependency>
          <dependency>
              <groupId>joda-time</groupId>
              <artifactId>joda-time</artifactId>
              <version>${joda-time.version}</version>
          </dependency>
          <dependency>
              <groupId>com.squareup.okhttp3</groupId>
              <artifactId>okhttp</artifactId>
              <version>${okhttp.version}</version>
          </dependency>
          <dependency>
              <groupId>com.squareup.okio</groupId>
              <artifactId>okio</artifactId>
              <version>${okio.version}</version>
          </dependency>
          <dependency>
              <groupId>com.aliyun.oss</groupId>
              <artifactId>aliyun-sdk-oss</artifactId>
              <version>${aliyun-sdk-oss.version}</version>
          </dependency>
          <dependency>
              <groupId>com.aliyun</groupId>
              <artifactId>aliyun-java-sdk-core</artifactId>
              <version>${aliyun-java-sdk-core.version}</version>
          </dependency>
          <dependency>
              <groupId>com.aliyun</groupId>
              <artifactId>aliyun-java-sdk-dm</artifactId>
              <version>${aliyun-java-sdk-dm.version}</version>
          </dependency>
      </dependencies>
    </dependencyManagement>

</project>

三、coin-exchange依赖

coin-exchang 是所有项目的父项目,在它里面添加依赖时需要谨慎,因为它的依赖会传递到我们所有的子项目里面

我们在coin-exchange里面依赖:

<dependencies>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.swagger/swagger-annotations -->
    <dependency>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-annotations</artifactId>
    </dependency>
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-annotation</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
    </dependency>
</dependencies>

大家不难发现,我们仅仅依赖了一些注解而已。

可以看到,我们的根目录实际只依赖了四个依赖:

file

知识扩展:

Maven中dependencymanagement和dependency的区别:

简单来说:
dependencyManagement 里只是声明依赖,并不实现引入,而dependencies相对于dependencyManagement,所有声明在dependencies里的依赖都会自动引入,并默认被所有的子项目继承

Maven 使用dependencyManagement 元素来提供了一种管理依赖版本号的方式。通常会在一个组织或者项目的最顶层的父POM 中看到dependencyManagement 元素。使用pom.xml 中的dependencyManagement 元素能让所有在子项目中引用一个依赖而不用显式的列出版本号。Maven 会沿着父子层次向上走,直到找到一个拥有dependencyManagement 元素的项目,然后它就会使用在这个dependencyManagement 元素中指定的版本号。

相对于dependencyManagement,所有声明在dependencies里的依赖都会自动引入,并默认被所有的子项目继承。

完整 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.quantsmart</groupId>
    <artifactId>coin-exchange</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>
    <modules>
        <module>coin-iass</module>
        <module>coin-common</module>
        <module>coin-member</module>
        <module>coin-finance</module>
        <module>coin-chan</module>
        <module>coin-task</module>
        <module>coin-statistics</module>
        <module>match-engine</module>
        <module>exchange-engine</module>
        <module>coin-admin</module>
    </modules>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR3</spring-cloud.version>
        <com-alibaba-cloud.version>2.2.0.RELEASE</com-alibaba-cloud.version>
        <mybatis-plus-boot-stater.version>3.3.2</mybatis-plus-boot-stater.version>
        <druid-boot-stater.version>1.1.23</druid-boot-stater.version>
        <redisson-spring-boot-starter.version>3.13.3</redisson-spring-boot-starter.version>
        <jetcache-starter-redis.version>2.6.0</jetcache-starter-redis.version>
        <disruptor.version>3.4.2</disruptor.version>
        <org.mapstruct.version>1.4.0.Beta3</org.mapstruct.version>
        <commons-beanutils.version>1.9.4</commons-beanutils.version>
        <swagger-annotations.version>1.5.20</swagger-annotations.version>
        <googleauth.version>1.1.5</googleauth.version>
        <net.sf.supercsv.version>2.4.0</net.sf.supercsv.version>
        <springside-utils.version>5.0.0-RC1</springside-utils.version>
        <aliyun-sdk-oss.version>3.1.0</aliyun-sdk-oss.version>
        <aliyun-java-sdk-core.version>4.0.3</aliyun-java-sdk-core.version>
        <aliyun-java-sdk-dm.version>3.3.1</aliyun-java-sdk-dm.version>
        <joda-time.version>2.10</joda-time.version>
        <okhttp.version>3.11.0</okhttp.version>
        <okio.version>1.15.0</okio.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.swagger/swagger-annotations -->
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-annotation</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
      <dependencies>
          <dependency>
              <groupId>org.springframework.cloud</groupId>
              <artifactId>spring-cloud-dependencies</artifactId>
              <version>${spring-cloud.version}</version>
              <type>pom</type>
              <scope>import</scope>
          </dependency>
          <dependency>
              <groupId>com.alibaba.cloud</groupId>
              <artifactId>spring-cloud-alibaba-dependencies</artifactId>
              <version>${com-alibaba-cloud.version}</version>
              <type>pom</type>
              <scope>import</scope>
          </dependency>
          <dependency>
              <groupId>io.swagger</groupId>
              <artifactId>swagger-annotations</artifactId>
              <version>${swagger-annotations.version}</version>
          </dependency>
          <dependency>
              <groupId>com.baomidou</groupId>
              <artifactId>mybatis-plus-boot-starter</artifactId>
              <version>${mybatis-plus-boot-stater.version}</version>
          </dependency>
          <dependency>
              <groupId>com.baomidou</groupId>
              <artifactId>mybatis-plus-annotation</artifactId>
              <version>${mybatis-plus-boot-stater.version}</version>
          </dependency>
          <!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter -->
          <dependency>
              <groupId>com.alibaba</groupId>
              <artifactId>druid-spring-boot-starter</artifactId>
              <version>${druid-boot-stater.version}</version>
          </dependency>

          <dependency>
              <groupId>commons-beanutils</groupId>
              <artifactId>commons-beanutils</artifactId>
              <version>${commons-beanutils.version}</version>
          </dependency>
          <!-- https://mvnrepository.com/artifact/org.redisson/redisson-spring-boot-starter -->
          <dependency>
              <groupId>org.redisson</groupId>
              <artifactId>redisson-spring-boot-starter</artifactId>
              <version>${redisson-spring-boot-starter.version}</version>
          </dependency>

          <!-- https://mvnrepository.com/artifact/com.alicp.jetcache/jetcache-starter-redis -->
          <dependency>
              <groupId>com.alicp.jetcache</groupId>
              <artifactId>jetcache-starter-redis</artifactId>
              <version>${jetcache-starter-redis.version}</version>
          </dependency>
          <!-- https://mvnrepository.com/artifact/com.lmax/disruptor -->
          <dependency>
              <groupId>com.lmax</groupId>
              <artifactId>disruptor</artifactId>
              <version>${disruptor.version}</version>
          </dependency>
          <dependency>
              <groupId>io.springfox</groupId>
              <artifactId>springfox-swagger2</artifactId>
              <version>${swagger2.version}</version>
          </dependency>
          <dependency>
              <groupId>io.springfox</groupId>
              <artifactId>springfox-swagger-ui</artifactId>
              <version>${swagger2.version}</version>
          </dependency>

          <!--mapStruct依赖-->
          <dependency>
              <groupId>org.mapstruct</groupId>
              <artifactId>mapstruct-jdk8</artifactId>
              <version>${org.mapstruct.version}</version>
          </dependency>
          <dependency>
              <groupId>org.mapstruct</groupId>
              <artifactId>mapstruct-processor</artifactId>
              <version>${org.mapstruct.version}</version>
              <scope>provided</scope>
          </dependency>

          <dependency>
              <groupId>net.sf.supercsv</groupId>
              <artifactId>super-csv</artifactId>
              <version>${net.sf.supercsv.version}</version>
          </dependency>

          <dependency>
              <groupId>io.springside</groupId>
              <artifactId>springside-utils</artifactId>
              <version>${springside-utils.version}</version>
          </dependency>

          <dependency>
              <groupId>org.flywaydb</groupId>
              <artifactId>flyway-core</artifactId>
              <version>${flyway.version}</version>
          </dependency>
          <dependency>
              <groupId>joda-time</groupId>
              <artifactId>joda-time</artifactId>
              <version>${joda-time.version}</version>
          </dependency>
          <dependency>
              <groupId>com.squareup.okhttp3</groupId>
              <artifactId>okhttp</artifactId>
              <version>${okhttp.version}</version>
          </dependency>
          <dependency>
              <groupId>com.squareup.okio</groupId>
              <artifactId>okio</artifactId>
              <version>${okio.version}</version>
          </dependency>
          <dependency>
              <groupId>com.aliyun.oss</groupId>
              <artifactId>aliyun-sdk-oss</artifactId>
              <version>${aliyun-sdk-oss.version}</version>
          </dependency>
          <dependency>
              <groupId>com.aliyun</groupId>
              <artifactId>aliyun-java-sdk-core</artifactId>
              <version>${aliyun-java-sdk-core.version}</version>
          </dependency>
          <dependency>
              <groupId>com.aliyun</groupId>
              <artifactId>aliyun-java-sdk-dm</artifactId>
              <version>${aliyun-java-sdk-dm.version}</version>
          </dependency>
      </dependencies>
    </dependencyManagement>

</project>

四、coin-common的依赖

coin-common 以后将会让所有的xxx-service依赖,因此我们需要提取xxx-service里面所有的公共依赖。现在我们来思考一下,作为一个微服务或中台服务,都需要那些依赖:

①、服务注册

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

②、配置文件拉取

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>

③、服务保护(限流、熔断)

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

④、服务保护(鉴权)

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>

⑤、数据库的访问

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

⑥、缓存的使用

<dependency>
    <groupId>com.alicp.jetcache</groupId>
    <artifactId>jetcache-starter-redis</artifactId>
</dependency>

⑦、工具类

<dependency>
    <groupId>io.springside</groupId>
    <artifactId>springside-utils</artifactId>
</dependency>

⑧、远程调用

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

coin-common/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>coin-exchange</artifactId>
        <groupId>com.quantsmart</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>coin-common</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alicp.jetcache</groupId>
            <artifactId>jetcache-starter-redis</artifactId>
        </dependency>

        <dependency>
            <groupId>io.springside</groupId>
            <artifactId>springside-utils</artifactId>
        </dependency>
    </dependencies>
</project>

file

五、xxx-service的依赖

在所有的xxx-service 里面依赖coin-common

六、打包插件

我们的模块以后需要单独的运行起来,因此我们还需要添加一个打包插件:
file

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

涉及的项目包含:

  • coin-admin
  • coin-chan
  • coin-finance
  • coin-member
  • coin-statistics
  • coin-task
  • exchange-engine
  • match-engine

coin-exchange/exchange-engine/exchange-service/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>exchange-engine</artifactId>
        <groupId>com.quantsmart</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>exchange-service</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.quantsmart</groupId>
            <artifactId>exchange-api</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.quantsmart</groupId>
            <artifactId>coin-common</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

为者常成,行者常至