vlambda博客
学习文章列表

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本



你真的很特别


本节源码下载:

https://github.com/icat-xb/dubbo-parent/tree/dubbo-parent-ver1.0 


工具包下载:

链接:https://pan.baidu.com/s/11B-Kn8LJEtPBtfdx3jhDzw

提取码:8sca

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本 Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本
今天我们把之前的 dubbo-demo-consumerdubbo-demo-provider重复的接口抽取出来以及两个项目的 maven依赖包的版本也是一样的,我们也需要单独抽取出来,统一维护。

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本

创建maven项目

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本
1.首先创建一个maven父项目dubbo-parent
2.因为是父项目只起管理项目的作用,Packaging这里选 pom
3.删掉src文件夹

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本


Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本

创建三个maven子项目

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本

dubbo-demo-consumer,

dubbo-demo-provider,

dubbo-demo-api

1.依次 Maven >> New Maven Module Project

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本


2.勾选 Create a simple project (skip archetype selection)
3.填好项目名 >> Finish

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本


三个子项目创建好后如图:

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本


把之前 dubbo-demo-consumer,dubbo-demo-provider 两个项目复制过来,如图:

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本


抽取重复接口

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本

抽取重复接口DemoProviderService

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本
在子项目 dubbo-demo-api 下定义接口DemoProviderService
package com.icat.service;

/**
 * 服务提供者/消费者接口
 * @author icat
 *
 */


public interface DemoProviderService {
  
  public String sayHello(String name);

}
删掉 dubbo-demo-consumer,dubbo-demo-provider下的DemoProviderService 接口

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本

pom.xml分别添加依赖

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本
同时在这两个子项目的pom.xml分别添加依赖:
<dependency>
      <groupId>com.icat</groupId>
      <artifactId>dubbo-demo-api</artifactId>
      <version>0.0.1-SNAPSHOT</version>
</dependency>



统一依赖包版本

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本

添加依赖

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本
dubbo-parent 项目 pom.xml添加依赖:
<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.icat</groupId>
  <artifactId>dubbo-parent</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>

  <modules>
    <module>dubbo-demo-consumer</module>
    <module>dubbo-demo-provider</module>
    <module>dubbo-demo-api</module>
  </modules>

  <!-- 依赖版本管理 -->
  <properties>
    <dubbo-demo-api.version>0.0.1-SNAPSHOT</dubbo-demo-api.version>
    <dubbo.version>2.6.0</dubbo.version>
    <zkclient.version>0.10</zkclient.version>
    <curator-framework.version>4.0.1</curator-framework.version>
    <fastjson.version>1.2.46</fastjson.version>
    <log4j.version>1.2.17</log4j.version>
    <slf4j-api.version>1.7.25</slf4j-api.version>
    <commons-lang3.version>3.4</commons-lang3.version>
    <netty-all.version>4.0.35.Final</netty-all.version>
  </properties>

  <!-- 依赖管理 -->
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.icat</groupId>
        <artifactId>dubbo-demo-api</artifactId>
        <version>${dubbo-demo-api.version}</version>
      </dependency>
      <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>dubbo</artifactId>
        <version>${dubbo.version}</version>
      </dependency>
      <dependency>
        <groupId>com.101tec</groupId>
        <artifactId>zkclient</artifactId>
        <version>${zkclient.version}</version>
      </dependency>
      <dependency>
        <groupId>org.apache.curator</groupId>
        <artifactId>curator-framework</artifactId>
        <version>${curator-framework.version}</version>
      </dependency>
      <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>${fastjson.version}</version>
      </dependency>
      <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>${log4j.version}</version>
      </dependency>
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j-api.version}</version>
      </dependency>
      <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>${commons-lang3.version}</version>
      </dependency>
      <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-all</artifactId>
        <version>${netty-all.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本

修改依赖

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本
dubbo-demo-provider项目pom.xml修改依赖:
<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>
  <parent>
    <groupId>com.icat</groupId>
    <artifactId>dubbo-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>dubbo-demo-provider</artifactId>

  <dependencies>
    <dependency>
      <groupId>com.icat</groupId>
      <artifactId>dubbo-demo-api</artifactId>
    </dependency>
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>dubbo</artifactId>
    </dependency>
    <dependency>
      <groupId>com.101tec</groupId>
      <artifactId>zkclient</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.curator</groupId>
      <artifactId>curator-framework</artifactId>
    </dependency>
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
    </dependency>
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-all</artifactId>
    </dependency>
  </dependencies>
</project>

dubbo-demo-consumer项目 pom.xml修改依赖:
<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>
  <parent>
    <groupId>com.icat</groupId>
    <artifactId>dubbo-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>dubbo-demo-consumer</artifactId>

  <dependencies>
    <dependency>
      <groupId>com.icat</groupId>
      <artifactId>dubbo-demo-api</artifactId>
    </dependency>
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>dubbo</artifactId>
    </dependency>
    <dependency>
      <groupId>com.101tec</groupId>
      <artifactId>zkclient</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.curator</groupId>
      <artifactId>curator-framework</artifactId>
    </dependency>
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
    </dependency>
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-all</artifactId>
    </dependency>
  </dependencies>
</project>


测试

1.首先启动zookeeper服务;
2.然后运行服务提供者测试类 ProviderTest,发布服务注册到zookeeper注册中心;
3.最后运行服务消费者测试类 ConsumerTest;

Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本


Dubbo学习笔记(四)--- 抽取重复接口以及统一依赖版本

测试ok!

粉丝特别福利

最新整理了2000G的java从入门到大神所需干货;

涵盖java初级,中级,高级,架构课程

涵盖j2ee项目20个++;

涵盖springcloud项目课程6个++

涵盖初级到BAT笔试面试题;

涵盖简历模版,项目素材

获取方式:扫描下方二维码,在台打开回复 【福利即可领取,资料持续更新!


获取2000Gjava从菜鸡到大神资料

(回复  福利  获取)