• 超详细,新手都能看懂 !使用SpringBoot+Dubbo 搭建一个简单的分布式服务


                    <section class="" data-mpa-template-id="1653" data-mpa-color="#ffffff" data-mpa-category="引导" style="letter-spacing: 0.544px;white-space: normal;font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;word-spacing: 2px;background-color: rgb(255, 255, 255);widows: 1;"></section><p style="text-align: left;"><span style="font-size: 12px;color: rgb(136, 136, 136);">来自:JavaGuide</span><br></p><p style="text-align: left;"><span style="font-size: 12px;color: rgb(136, 136, 136);">Github 地址:https://github.com/Snailclimb/springboot-integration-examples</span></p><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">目录:</strong></p><ul style="" class="list-paddingleft-2"><li><p>使用 SpringBoot+Dubbo 搭建一个简单分布式服务</p></li><li><p>实战之前,先来看几个重要的概念</p></li><ul style="list-style-type: square;" class="list-paddingleft-2"><li><p>什么是分布式?</p></li><li><p>什么是 Duboo?</p></li><li><p>Dubbo 架构</p></li><li><p>什么是 RPC?</p></li><li><p>为什么要用 Dubbo?</p></li></ul><li><p>开始实战 1 :zookeeper 环境安装搭建</p></li><ul style="list-style-type: square;" class="list-paddingleft-2"><li><p>1. 下载</p></li><li><p>2. 解压</p></li><li><p>3. 进入zookeeper目录,创建data文件夹。</p></li><li><p>4. 进入/zookeeper/conf目录下,复制zoo_sample.cfg,命名为zoo.cfg</p></li><li><p>5. 修改配置文件</p></li><li><p>6. 启动测试</p></li></ul><li><p>开始实战 2 :实现服务接口 dubbo-interface</p></li><ul style="list-style-type: square;" class="list-paddingleft-2"><li><p>1. dubbo-interface 项目创建</p></li><li><p>2. 创建接口类</p></li><li><p>3. 将项目打成 jar 包供其他项目使用</p></li></ul><li><p>开始实战 3 :实现服务提供者 dubbo-provider</p></li><ul style="list-style-type: square;" class="list-paddingleft-2"><li><p>1. dubbo-provider 项目创建</p></li><li><p>2. pom 文件引入相关依赖</p></li><li><p>3. 在 application.properties 配置文件中配置 dubbo 相关信息</p></li><li><p>4. 实现接口</p></li><li><p>5. 服务提供者启动类编写</p></li></ul><li><p>开始实战 4 :实现服务消费者 dubbo-consumer</p></li><ul style="list-style-type: square;" class="list-paddingleft-2"><li><p>4. 编写一个简单 Controller 调用远程服务</p></li><li><p>5. 服务消费者启动类编写</p></li><li><p>6. 测试效果</p></li></ul></ul><h1 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.6em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">使用 SpringBoot+Dubbo 搭建一个简单分布式服务</span></h1><h2 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.4em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">实战之前,先来看几个重要的概念</span></h2><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">开始实战之前,我们先来简单的了解一下这样几个概念:Dubbo、RPC、分布式、由于本文的目的是带大家使用SpringBoot+Dubbo 搭建一个简单的分布式服务,所以这些概念我只会简单给大家普及一下,不会做深入探究。</p><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">什么是分布式?</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">分布式或者说 SOA 分布式重要的就是面向服务,说简单的分布式就是我们把整个系统拆分成不同的服务然后将这些服务放在不同的服务器上减轻单体服务的压力提高并发量和性能。比如电商系统可以简单地拆分成订单系统、商品系统、登录系统等等。</p><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">我们可以使用 Dubbo作为分布式系统的桥梁,那么什么是 Dubbo 呢?</strong></p><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">什么是 Duboo?</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">Apache Dubbo (incubating) |ˈdʌbəʊ| 是一款高性能、轻量级的开源Java RPC 框架,它提供了三大核心能力:面向接口的远程方法调用,智能容错和负载均衡,以及服务自动注册和发现。简单来说 Dubbo 是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案。</p><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">Dubbo 目前已经有接近 23k 的 Star ,Dubbo的Github 地址:https://github.com/apache/incubator-dubbo。另外,在开源中国举行的2018年度最受欢迎中国开源软件这个活动的评选中,Dubbo 更是凭借其超高人气仅次于 vue.js 和 ECharts 获得第三名的好成绩。</p><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">Dubbo 是由阿里开源,后来加入了 Apache 。正式由于 Dubbo 的出现,才使得越来越多的公司开始使用以及接受分布式架构。</p><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">下面我们简单地来看一下 Dubbo 的架构,加深对 Dubbo 的理解。</strong></p><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">Dubbo 架构</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">下面我们再来看看 Dubbo 的架构,我们后面会使用 zookeeper 作为注册中心,这也是 Dubbo 官方推荐的一种方式。</p><figure style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-ratio="0.673036093418259" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165114350-2098709541.png" data-type="png" data-w="471" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  471px !important; height: auto !important; visibility: visible !important;" title="Dubbo 架构" _width="471px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165133774-1227294830.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">Dubbo 架构</figcaption></figure><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">上述节点简单说明:</strong></p><ul style="" class="list-paddingleft-2"><li><p><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">Provider</strong>&nbsp;暴露服务的服务提供方</p></li><li><p><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">Consumer</strong>&nbsp;调用远程服务的服务消费方</p></li><li><p><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">Registry</strong>&nbsp;服务注册与发现的注册中心</p></li><li><p><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">Monitor</strong>&nbsp;统计服务的调用次数和调用时间的监控中心</p></li><li><p><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">Container</strong>&nbsp;服务运行容器</p></li></ul><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">调用关系说明:</strong></p><ol style="" class="list-paddingleft-2"><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">服务容器负责启动,加载,运行服务提供者。</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">服务提供者在启动时,向注册中心注册自己提供的服务。</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">服务消费者在启动时,向注册中心订阅自己所需的服务。</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">注册中心返回服务提供者地址列表给消费者,如果有变更,注册中心将基于长连接推送变更数据给消费者。</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">服务消费者,从提供者地址列表中,基于软负载均衡算法,选一台提供者进行调用,如果调用失败,再选另一台调用。</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心。</span></p></li></ol><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">我们在讲 Dubbo 的时候提到了 Dubbo 实际上是一款 RPC 框架,那么RPC 究竟是什么呢?相信看了下面我对 RPC 的介绍你就明白了!</strong></p><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">什么是 RPC?</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">RPC(Remote Procedure Call)—远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议。比如两个不同的服务A,B部署在两台不同的机器上,那么服务 A 如果想要调用服务 B 中的某个方法该怎么办呢?使用 HTTP请求 当然可以,但是可能会比较慢而且一些优化做的并不好。RPC 的出现就是为了解决这个问题。</p><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">为什么要用 Dubbo?</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">如果你要开发分布式程序,你也可以直接基于 HTTP 接口进行通信,但是为什么要用 Dubbo呢?</p><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">我觉得主要可以从 Dubbo 提供的下面四点特性来说为什么要用 Dubbo:</p><ol style="" class="list-paddingleft-2"><li><p><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">负载均衡</strong>——同一个服务部署在不同的机器时该调用那一台机器上的服务</p></li><li><p><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">服务调用链路生成</strong>——服务之间互相是如何调用的</p></li><li><p><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">服务访问压力以及时长统计</strong>——当前系统的压力主要在哪里,如何来扩容和优化</p></li><li><p><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">服务降级</strong>——某个服务挂掉之后调用备用服务</p></li></ol><h2 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.4em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">开始实战 1 :zookeeper 环境安装搭建</span></h2><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">我使用的是 CentOS 7.4 阿里云服务器,注意:如果你也同样阿里云服务器必须配置一个安全组,不然你的应用程序会无法访问你的 zookeeper 服务器,这一点我在后面也提到了。</p><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">1. 下载</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">通过 http://mirror.bit.edu.cn/apache/zookeeper/&nbsp;这个链接下载,然后上传到Linux上。(可以说那个 Xhell 附带的文件传输功能)</p><figure style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-ratio="0.4641509433962264" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165154971-742311587.png" data-type="png" data-w="795" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  677px !important; height: auto !important; visibility: visible !important;" title="zookeeper下载" _width="677px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165211434-722946569.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">zookeeper下载</figcaption></figure><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">或者直接在Linux中使用&nbsp;<code style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 2px 4px;font-size: inherit;color: rgb(233, 105, 0);line-height: inherit;word-wrap: break-word;border-radius: 4px;background: rgb(248, 248, 248);">wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.12/zookeeper-3.4.12.tar.gz</code>&nbsp;命令下载(版本号 3.4.12 是我写这篇文章的时候最新的稳定版本,各位可以根据实际情况修改)</p><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">2. 解压</span></h3><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs css" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(170, 170, 170);line-height: 18px;border-radius: 0px;background: rgb(34, 34, 34);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;word-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;"><span class="hljs-selector-tag"><span class="hljs-selector-tag">tar</span></span>&nbsp;<span class="hljs-selector-tag"><span class="hljs-selector-tag">-zxvf</span></span>&nbsp;<span class="hljs-selector-tag"><span class="hljs-selector-tag">zookeeper-3</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.4</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.12-alpha</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.tar</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.gz</span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><figure style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-ratio="0.44605475040257647" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165234543-1727215078.png" data-type="png" data-w="621" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  621px !important; height: auto !important; visibility: visible !important;" title="解压之后" _width="621px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165252481-25653247.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">解压之后</figcaption></figure><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">解压完毕之后修改一下解压之后所得的文件夹名</p><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs css" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(170, 170, 170);line-height: 18px;border-radius: 0px;background: rgb(34, 34, 34);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;word-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;"><span class="hljs-selector-tag"><span class="hljs-selector-tag">mv</span></span>&nbsp;<span class="hljs-selector-tag"><span class="hljs-selector-tag">zookeeper-3</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.4</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.12</span></span>&nbsp;<span class="hljs-selector-tag"><span class="hljs-selector-tag">zookeeper</span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">删除 zookeeper 安装包</p><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs css" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(170, 170, 170);line-height: 18px;border-radius: 0px;background: rgb(34, 34, 34);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;word-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;"><span class="hljs-selector-tag"><span class="hljs-selector-tag">rm</span></span>&nbsp;<span class="hljs-selector-tag"><span class="hljs-selector-tag">-rf</span></span>&nbsp;<span class="hljs-selector-tag"><span class="hljs-selector-tag">zookeeper-3</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.4</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.12</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.tar</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.gz</span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">3. 进入zookeeper目录,创建data文件夹。</span></h3><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs haskell" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(170, 170, 170);line-height: 18px;border-radius: 0px;background: rgb(34, 34, 34);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;word-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;"><span class="hljs-title"><span class="hljs-title">mkdir</span></span>&nbsp;<span class="hljs-class"><span class="hljs-keyword"><span class="hljs-class"><span class="hljs-keyword">data</span></span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">进入 data 文件夹 然后执行<code style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 2px 4px;font-size: inherit;color: rgb(233, 105, 0);line-height: inherit;word-wrap: break-word;border-radius: 4px;background: rgb(248, 248, 248);">pwd</code>命令,复制所得的当前目录位置(就是我用红色圈出来的文字)</p><figure style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-ratio="0.11546840958605664" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165313810-124663772.png" data-type="png" data-w="459" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  459px !important; height: auto !important; visibility: visible !important;" title="进入  data 文件夹 然后执行pwd命令" _width="459px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165330215-1596402228.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">进入 data 文件夹 然后执行pwd命令</figcaption></figure><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">4. 进入/zookeeper/conf目录下,复制zoo_sample.cfg,命名为zoo.cfg</span></h3><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs css" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(170, 170, 170);line-height: 18px;border-radius: 0px;background: rgb(34, 34, 34);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;word-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;"><span class="hljs-selector-tag"><span class="hljs-selector-tag">cp</span></span>&nbsp;<span class="hljs-selector-tag"><span class="hljs-selector-tag">zoo_sample</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.cfg</span></span>&nbsp;<span class="hljs-selector-tag"><span class="hljs-selector-tag">zoo</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.cfg</span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">5. 修改配置文件</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">使用&nbsp;<code style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 2px 4px;font-size: inherit;color: rgb(233, 105, 0);line-height: inherit;word-wrap: break-word;border-radius: 4px;background: rgb(248, 248, 248);">vim zoo.cfg</code>&nbsp;命令修改配置文件</p><blockquote style="box-sizing: border-box;margin-top: 1em;margin-bottom: 1em;padding: 15px 15px 15px 1rem;color: rgb(129, 145, 152);border-left- 6px;border-left-color: rgb(220, 230, 240);font-size: 0.9em;line-height: inherit;background: rgb(242, 247, 251);overflow: auto;word-wrap: normal;word-break: normal;white-space: normal;"><p style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">vim 文件------&gt;进入文件-----&gt;命令模式------&gt;按i进入编辑模式-----&gt;编辑文件 -------&gt;按Esc进入底行模式-----&gt;输入:wq/q! (输入wq代表写入内容并退出,即保存;输入q!代表强制退出不保存。)</p></blockquote><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">修改配置文件中的 data 属性:</p><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs haskell" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 2px 4px;font-size: 14px;color: rgb(233, 105, 0);line-height: 18px;border-radius: 0px;background: rgb(248, 248, 248);font-family: Consolas, Inconsolata, Courier, monospace;letter-spacing: 0px;word-wrap: normal !important;display: block !important;word-break: normal !important;overflow: auto !important;"><span class="hljs-title"><span class="hljs-title">dataDir</span></span>=/usr/local/zookeeper/<span class="hljs-class"><span class="hljs-keyword"><span class="hljs-class"><span class="hljs-keyword">data</span></span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">6. 启动测试</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">进入 /zookeeper/bin 目录然后执行下面的命令</p><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs dos" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(170, 170, 170);line-height: 18px;border-radius: 0px;background: rgb(34, 34, 34);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;word-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">./zkServer.sh&nbsp;<span class="hljs-built_in"><span class="hljs-built_in">start</span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">执行&nbsp;<code style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 2px 4px;font-size: inherit;color: rgb(233, 105, 0);line-height: inherit;word-wrap: break-word;border-radius: 4px;background: rgb(248, 248, 248);">./zkServer.sh status</code>&nbsp;查看当前 zookeeper 状态。</p><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">或者运行&nbsp;<code style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 2px 4px;font-size: inherit;color: rgb(233, 105, 0);line-height: inherit;word-wrap: break-word;border-radius: 4px;background: rgb(248, 248, 248);">netstat -lntup</code>&nbsp;命令查看网络状态,可以看到 zookeeper 的端口号 2181 已经被占用</p><figure style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-ratio="0.31521739130434784" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165347967-1962757159.png" data-type="png" data-w="736" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  677px !important; height: auto !important; visibility: visible !important;" title="运行 netstat   -lntup命令查看网络状态" _width="677px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165413182-468143982.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">运行 netstat -lntup命令查看网络状态</figcaption></figure><hr style="box-sizing: border-box;margin-top: 1.5rem;margin-bottom: 1.5rem;border-style: dashed none none;border-top-color: rgb(165, 165, 165);border-right- initial;border-right-color: initial;border-left- initial;border-left-color: initial;border-bottom- initial;border-bottom-color: initial;height: 1px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">注意没有关闭防火墙可能出现的问题!!!</p><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">如果你使用的阿里云服务器注意配置相关安全组:</p><ol style="" class="list-paddingleft-2"><li><p>进入本实例安全组页面<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;"></p><figure style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;"><img class="" data-ratio="0.5202839756592292" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165428638-1315274035.png" data-type="png" data-w="986" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  677px !important; height: auto !important; visibility: visible !important;" title="进入本实例安全组页面" _width="677px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165650166-1784360772.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">进入本实例安全组页面</figcaption></figure></li><li><p>选择配置规则<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;"></p><figure style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;"><img class="" data-ratio="0.2" data-src=“(https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165708534-1941300028.png" data-type="png" data-w="1080" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  677px !important; height: auto !important; visibility: visible !important;" title="选择配置规则" _width="677px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165728407-1570337848.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">选择配置规则</figcaption></figure></li><li><p>选择添加安全组规则,然后按照下图配置<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;"></p><figure style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;"><img class="" data-ratio="0.5764828303850156" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165750464-1638832168.png" data-type="png" data-w="961" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  677px !important; height: auto !important; visibility: visible !important;" title="选择添加安全组规则,然后按照下图配置" _width="677px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165806649-1205152944.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">选择添加安全组规则,然后按照下图配置</figcaption></figure></li></ol><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">在开始实战之前提个建议:尽量新建一个文件夹,然后后面将接口项目、服务提供者以及服务消费者都放在这个文件夹。<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;"></p><figure style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-ratio="0.2627627627627628" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165829566-1055542272.png" data-type="png" data-w="666" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  666px !important; height: auto !important; visibility: visible !important;" title="项目概览" _width="666px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030165846934-1283762617.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">项目概览</figcaption></figure><h2 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.4em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">开始实战 2 :实现服务接口 dubbo-interface</span></h2><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">主要分为下面几步:</p><ol style="" class="list-paddingleft-2"><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">创建 Maven 项目;</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">创建接口类</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">将项目打成 jar 包供其他项目使用</span></p></li></ol><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">项目结构:</p><figure style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-ratio="1.278443113772455" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170109292-2106809366.png" data-type="png" data-w="334" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  334px !important; height: auto !important; visibility: visible !important;" title="dubbo-provider 项目结构" _width="334px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170125624-428439287.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">dubbo-provider 项目结构</figcaption></figure><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">dubbo-interface 后面被打成 jar 包,它的作用只是提供接口。</p><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">1. dubbo-interface 项目创建</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;color: inherit;font-size: inherit;line-height: inherit;">File-&gt;New-&gt;Module…</strong>&nbsp;,然后选择 Maven类型的项目,其他的按照提示一步一步走就好。</p><figure style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-ratio="1.200750469043152" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170006808-1282783836.png" data-type="png" data-w="533" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  533px !important; height: auto !important; visibility: visible !important;" title="第一步" _width="533px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170147173-1161286499.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">第一步</figcaption></figure><figure style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-ratio="0.8888888888888888" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170211144-1367818826.png" data-type="png" data-w="819" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  677px !important; height: auto !important; visibility: visible !important;" title="第二步" _width="677px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170230049-1632488850.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">第二步</figcaption></figure><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">2. 创建接口类</span></h3><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs java" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(170, 170, 170);line-height: 18px;border-radius: 0px;background: rgb(34, 34, 34);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;word-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">package</span></span></span>&nbsp;top.snailclimb.service;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">public</span></span></span>&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-class"><span class="hljs-keyword"><span class="hljs-class"><span class="hljs-keyword">interface</span></span></span></span></span><span class="hljs-class"><span class="hljs-class">&nbsp;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(187, 17, 102);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-class"><span class="hljs-title"><span class="hljs-class"><span class="hljs-title">HelloService</span></span></span></span></span><span class="hljs-class"><span class="hljs-class">&nbsp;</span></span></span>{<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-function"><span class="hljs-keyword"><span class="hljs-function"><span class="hljs-keyword">public</span></span></span></span></span><span class="hljs-function"><span class="hljs-function">&nbsp;&nbsp;String&nbsp;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(187, 17, 102);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-function"><span class="hljs-title"><span class="hljs-function"><span class="hljs-title">sayHello</span></span></span></span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-function"><span class="hljs-params"><span class="hljs-function"><span class="hljs-params">(String&nbsp;name)</span></span></span></span></span></span>;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">}<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">3. 将项目打成 jar 包供其他项目使用</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">点击右边的 Maven Projects 然后选择 install ,这样 jar 宝就打好了。<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;"></p><figure style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-ratio="0.523598820058997" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170255117-1313402584.png" data-type="png" data-w="1356" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  677px !important; height: auto !important; visibility: visible !important;" title="" _width="677px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170314653-162585073.png" crossorigin="anonymous" data-fail="0"></figure><h2 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.4em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">开始实战 3 :实现服务提供者 dubbo-provider</span></h2><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">主要分为下面几步:</p><ol style="" class="list-paddingleft-2"><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">创建 springboot 项目;</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">加入 dubbo 、zookeeper以及接口的相关依赖 jar 包;</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">在 application.properties 配置文件中配置 dubbo 相关信息;</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">实现接口类;</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">服务提供者启动类编写</span></p></li></ol><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">项目结构:</p><figure style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-ratio="1.278443113772455" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170339658-1068958840.png" data-type="png" data-w="334" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  334px !important; height: auto !important; visibility: visible !important;" title="dubbo-provider 项目结构" _width="334px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170411092-313674721.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">dubbo-provider 项目结构</figcaption></figure><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">1. dubbo-provider 项目创建</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">创建一个 SpringBoot 项目,注意勾选上 web 模块。不会创建的话,可以查看下面这篇文章:,可以说很详细了。</p><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">https://blog.csdn.net/qq_34337272/article/details/79563606</p><figure style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-ratio="0.8888888888888888" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170427864-1408519458.png" data-type="png" data-w="819" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  677px !important; height: auto !important; visibility: visible !important;" title="注意勾选上 web 模块" _width="677px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170445092-1961636333.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">注意勾选上 web 模块</figcaption></figure><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">2. pom 文件引入相关依赖</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">需要引入 dubbo 、zookeeper以及接口的相关依赖 jar 包。注意将本项目和 dubbo-interface 项目的 dependency 依赖的 groupId 和 artifactId 改成自己的。dubbo 整合spring boot 的 jar 包在这里找dubbo-spring-boot-starter。zookeeper 的 jar包在 Maven 仓库&nbsp;搜索 zkclient 即可找到。</p><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs xml" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(170, 170, 170);line-height: 18px;border-radius: 0px;background: rgb(34, 34, 34);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;word-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">dependency</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">groupId</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span>top.snailclimb<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;/</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">groupId</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">artifactId</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span>dubbo-interface<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;/</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">artifactId</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">version</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span>1.0-SNAPSHOT<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;/</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">version</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;/</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">dependency</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(68, 68, 68);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">&lt;!--引入dubbo的依赖--&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">dependency</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">groupId</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span>com.alibaba.spring.boot<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;/</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">groupId</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">artifactId</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span>dubbo-spring-boot-starter<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;/</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">artifactId</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">version</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span>2.0.0<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;/</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">version</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;/</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">dependency</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(68, 68, 68);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">&lt;!--&nbsp;引入zookeeper的依赖&nbsp;--&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">dependency</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">groupId</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span>com.101tec<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;/</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">groupId</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">artifactId</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span>zkclient<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;/</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">artifactId</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">version</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span>0.10<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;/</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">version</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-tag">&lt;/</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-tag"><span class="hljs-name"><span class="hljs-tag"><span class="hljs-name">dependency</span></span></span></span></span><span class="hljs-tag"><span class="hljs-tag">&gt;</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">3. 在 application.properties 配置文件中配置 dubbo 相关信息</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">配置很简单,这主要得益于 springboot 整合 dubbo 专属的<code style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 2px 4px;font-size: inherit;color: rgb(233, 105, 0);line-height: inherit;word-wrap: break-word;border-radius: 4px;background: rgb(248, 248, 248);">@EnableDubboConfiguration</code>注解提供的 Dubbo 自动配置。</p><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs go" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 2px 4px;font-size: 14px;color: rgb(233, 105, 0);line-height: 18px;border-radius: 0px;background: rgb(248, 248, 248);font-family: Consolas, Inconsolata, Courier, monospace;letter-spacing: 0px;word-wrap: normal !important;display: block !important;word-break: normal !important;overflow: auto !important;">#&nbsp;配置端口<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">server.port=<span class="hljs-number"><span class="hljs-number">8333</span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-number"><span class="hljs-number">s</span></span>pring.dubbo.application.name=dubbo-provider<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">spring.dubbo.application.registry=zookeeper:<span class="hljs-comment"><span class="hljs-comment">//ip地址:2181</span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">4. 实现接口</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">注意:&nbsp;<code style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 2px 4px;font-size: inherit;color: rgb(233, 105, 0);line-height: inherit;word-wrap: break-word;border-radius: 4px;background: rgb(248, 248, 248);">@Service</code>&nbsp;注解使用的时 Dubbo 提供的而不是 Spring 提供的。另外,加了Dubbo 提供的&nbsp;<code style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 2px 4px;font-size: inherit;color: rgb(233, 105, 0);line-height: inherit;word-wrap: break-word;border-radius: 4px;background: rgb(248, 248, 248);">@Service</code>&nbsp;注解之后还需要加入</p><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs css" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(170, 170, 170);line-height: 18px;border-radius: 0px;background: rgb(34, 34, 34);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;word-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-selector-tag"><span class="hljs-selector-tag">package</span></span></span>&nbsp;<span class="hljs-selector-tag"><span class="hljs-selector-tag">top</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.snailclimb</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.service</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.impl</span></span>;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-selector-tag"><span class="hljs-selector-tag">import</span></span></span>&nbsp;<span class="hljs-selector-tag"><span class="hljs-selector-tag">com</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.alibaba</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.dubbo</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.config</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.annotation</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.Service</span></span>;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-selector-tag"><span class="hljs-selector-tag">import</span></span></span>&nbsp;<span class="hljs-selector-tag"><span class="hljs-selector-tag">org</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.springframework</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.stereotype</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.Component</span></span>;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-selector-tag"><span class="hljs-selector-tag">import</span></span></span>&nbsp;<span class="hljs-selector-tag"><span class="hljs-selector-tag">top</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.snailclimb</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.service</span></span><span class="hljs-selector-class"><span class="hljs-selector-class">.HelloService</span></span>;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(68, 68, 68);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">@<span class="hljs-keyword"><span class="hljs-keyword">Component</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(68, 68, 68);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">@<span class="hljs-keyword"><span class="hljs-keyword">Service</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">public</span></span></span>&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">class</span>&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(187, 17, 102);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">HelloServiceImpl</span>&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">implements</span>&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(187, 17, 102);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">HelloService</span>&nbsp;</span>{<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(68, 68, 68);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">@<span class="hljs-keyword"><span class="hljs-keyword">Override</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">public</span>&nbsp;String&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(187, 17, 102);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">sayHello</span><span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">(String&nbsp;name)</span>&nbsp;</span>{<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-selector-tag"><span class="hljs-selector-tag">return</span></span></span>&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(255, 204, 51);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">"<span class="hljs-selector-tag"><span class="hljs-selector-tag">Hello</span></span>&nbsp;"</span>&nbsp;+&nbsp;<span class="hljs-selector-tag"><span class="hljs-selector-tag">name</span></span>;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;}<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">}<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">5. 服务提供者启动类编写</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">注意:不要忘记加上&nbsp;<code style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 2px 4px;font-size: inherit;color: rgb(233, 105, 0);line-height: inherit;word-wrap: break-word;border-radius: 4px;background: rgb(248, 248, 248);">@EnableDubboConfiguration</code>&nbsp;注解开启Dubbo 的自动配置。</p><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs groovy" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(170, 170, 170);line-height: 18px;border-radius: 0px;background: rgb(34, 34, 34);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;word-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">package</span></span></span>&nbsp;top.snailclimb;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">import</span></span></span>&nbsp;com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">import</span></span></span>&nbsp;org.springframework.boot.SpringApplication;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">import</span></span></span>&nbsp;org.springframework.boot.autoconfigure.SpringBootApplication;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(68, 68, 68);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-meta"><span class="hljs-meta">@SpringBootApplication</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(68, 68, 68);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">//&nbsp;开启dubbo的自动配置</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(68, 68, 68);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">@EnableDubboConfiguration</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">public</span></span></span><span class="hljs-comment"><span class="hljs-comment">&nbsp;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">class</span></span></span><span class="hljs-comment"><span class="hljs-comment">&nbsp;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(187, 17, 102);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">DubboProviderApplication</span></span></span><span class="hljs-comment"><span class="hljs-comment">&nbsp;</span></span></span><span class="hljs-comment"><span class="hljs-comment">{</span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">public</span></span></span><span class="hljs-comment"><span class="hljs-comment">&nbsp;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">static</span></span></span><span class="hljs-comment"><span class="hljs-comment">&nbsp;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">void</span></span></span><span class="hljs-comment"><span class="hljs-comment">&nbsp;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(187, 17, 102);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">main</span></span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">(String[]&nbsp;args)</span></span></span><span class="hljs-comment"><span class="hljs-comment">&nbsp;</span></span></span><span class="hljs-comment"><span class="hljs-comment">{</span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SpringApplication.run(DubboProviderApplication.class,&nbsp;args);</span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-comment"><span class="hljs-comment">}</span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><h2 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.4em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">开始实战 4 :实现服务消费者 dubbo-consumer</span></h2><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">主要分为下面几步:</p><ol style="" class="list-paddingleft-2"><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">创建 springboot 项目;</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">加入 dubbo 、zookeeper以及接口的相关依赖 jar 包;</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">在 application.properties 配置文件中配置 dubbo 相关信息;</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">编写测试类;</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">服务消费者启动类编写</span></p></li><li><p><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">测试效果</span></p></li></ol><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">项目结构:</p><figure style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-ratio="1.240625" data-src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170502702-1276155566.png" data-type="png" data-w="320" style="box-sizing: border-box; margin-right: auto; margin-left: auto; border- 2px; border-style: solid; border-color: rgb(238, 238, 238); border-radius: 6px; font-size: inherit; color: inherit; line-height: inherit; display: block;  320px !important; height: auto !important; visibility: visible !important;" title="dubbo-consumer 项目结构" _width="320px" src="https://img2018.cnblogs.com/blog/1112483/201910/1112483-20191030170517638-1562888007.png" crossorigin="anonymous" data-fail="0"><figcaption style="box-sizing: border-box;margin-top: 10px;font-size: 0.7em;color: rgb(153, 153, 153);line-height: inherit;text-align: center;">dubbo-consumer 项目结构</figcaption></figure><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">第1,2,3 步和服务提供者的一样,这里直接从第 4 步开始。</p><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">4. 编写一个简单 Controller 调用远程服务</span></h3><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs java" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(170, 170, 170);line-height: 18px;border-radius: 0px;background: rgb(34, 34, 34);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;word-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">package</span></span></span>&nbsp;top.snailclimb.dubboconsumer;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">import</span></span></span>&nbsp;com.alibaba.dubbo.config.annotation.Reference;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">import</span></span></span>&nbsp;org.springframework.web.bind.annotation.RequestMapping;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">import</span></span></span>&nbsp;org.springframework.web.bind.annotation.RestController;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">import</span></span></span>&nbsp;top.snailclimb.service.HelloService;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(68, 68, 68);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-meta"><span class="hljs-meta">@RestController</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-meta"><span class="hljs-meta">public</span></span></span>&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-class"><span class="hljs-keyword"><span class="hljs-class"><span class="hljs-keyword">class</span></span></span></span></span><span class="hljs-class"><span class="hljs-class">&nbsp;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(187, 17, 102);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-class"><span class="hljs-title"><span class="hljs-class"><span class="hljs-title">HelloController</span></span></span></span></span><span class="hljs-class"><span class="hljs-class">&nbsp;</span></span></span>{<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(68, 68, 68);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-meta"><span class="hljs-meta">@Reference</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">private</span></span></span>&nbsp;HelloService&nbsp;helloService;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(68, 68, 68);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-meta"><span class="hljs-meta">@RequestMapping</span></span></span>(<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(255, 204, 51);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-string"><span class="hljs-string">"/hello"</span></span></span>)<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-function"><span class="hljs-keyword"><span class="hljs-function"><span class="hljs-keyword">public</span></span></span></span></span><span class="hljs-function"><span class="hljs-function">&nbsp;String&nbsp;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(187, 17, 102);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-function"><span class="hljs-title"><span class="hljs-function"><span class="hljs-title">hello</span></span></span></span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-function"><span class="hljs-params"><span class="hljs-function"><span class="hljs-params">()</span></span></span></span></span><span class="hljs-function"><span class="hljs-function">&nbsp;</span></span></span>{<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;hello&nbsp;=&nbsp;helloService.sayHello(<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(255, 204, 51);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-string"><span class="hljs-string">"world"</span></span></span>);<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(helloService.sayHello(<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(255, 204, 51);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-string"><span class="hljs-string">"SnailClimb"</span></span></span>));<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">return</span></span></span>&nbsp;hello;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;}<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">}<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">5. 服务消费者启动类编写</span></h3><pre style="box-sizing: border-box;margin-top: 0px;margin-bottom: 0px;padding: 0px;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;background-color: rgb(255, 255, 255);"><code class="hljs groovy" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(170, 170, 170);line-height: 18px;border-radius: 0px;background: rgb(34, 34, 34);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;word-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">package</span></span></span>&nbsp;top.snailclimb.dubboconsumer;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">import</span></span></span>&nbsp;com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">import</span></span></span>&nbsp;org.springframework.boot.SpringApplication;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">import</span></span></span>&nbsp;org.springframework.boot.autoconfigure.SpringBootApplication;<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(68, 68, 68);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-meta"><span class="hljs-meta">@SpringBootApplication</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(68, 68, 68);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-meta"><span class="hljs-meta">@EnableDubboConfiguration</span></span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-meta"><span class="hljs-meta">public</span></span></span>&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-class"><span class="hljs-keyword"><span class="hljs-class"><span class="hljs-keyword">class</span></span></span></span></span><span class="hljs-class"><span class="hljs-class">&nbsp;</span></span><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(187, 17, 102);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-class"><span class="hljs-title"><span class="hljs-class"><span class="hljs-title">DubboConsumerApplication</span></span></span></span></span><span class="hljs-class"><span class="hljs-class">&nbsp;</span></span></span><span class="hljs-class"><span class="hljs-class">{</span></span><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">public</span></span></span>&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">static</span></span></span>&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(102, 68, 170);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><span class="hljs-keyword"><span class="hljs-keyword">void</span></span></span>&nbsp;<span class="" style="box-sizing: border-box;font-size: inherit;color: rgb(187, 17, 102);line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">main</span><span class="" style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">(String[]&nbsp;args)</span>&nbsp;</span>{<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"><br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SpringApplication.run(DubboConsumerApplication.<span class="hljs-keyword"><span class="hljs-keyword">class</span></span>,&nbsp;args);<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;}<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;">}<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;word-wrap: inherit !important;word-break: inherit !important;"></code></pre><h3 style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-weight: bold;font-size: 1.3em;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;">6. 测试效果</span></h3><p style="box-sizing: border-box;margin-top: 1.5em;margin-bottom: 1.5em;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;white-space: normal;background-color: rgb(255, 255, 255);">浏览器访问 http://localhost:8330/hello 页面返回 Hello world,控制台输出 Hello SnailClimb,和预期一直,使用SpringBoot+Dubbo 搭建第一个简单的分布式服务实验成功!</p><hr style="border-style: solid;border- 1px 0 0;border-color: rgba(0,0,0,0.1);-webkit-transform-origin: 0 0;-webkit-transform: scale(1, 0.5);transform-origin: 0 0;transform: scale(1, 0.5);"><section style="margin-right: 8px;margin-left: 8px;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);font-size: 16px;color: rgb(62, 62, 62);text-align: right;"></section><section style="margin-right: 8px;margin-left: 8px;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);font-size: 16px;color: rgb(62, 62, 62);text-align: right;"><br></section>
    

    原文地址:https://mp.weixin.qq.com/s/5JAbJ4_7QRNf5BVFOAEqVg

  • 相关阅读:
    redis集群规范
    mongodb的基本使用
    redis进阶
    redis基本使用
    selenium的基本使用
    C++入门
    C语言入门
    MATLAB中矩阵reshape的顺序规律
    Tensorflow:ImportError: DLL load failed: 找不到指定的模块 Failed to load the native TensorFlow runtime
    差分定位和精密定位
  • 原文地址:https://www.cnblogs.com/jpfss/p/11765920.html
Copyright © 2020-2023  润新知