1、使用框架:springmvc+spring+zookeeper+dubbo ,使用maven管理项目
2、需引入jar包:pom.xml
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
</dependency>
3、system.properties配置系统参数
dubbo.application.name=xxx //应用名
dubbo.registry.zookeeper.address=zookeeper://10.16.68.137:2181 //zk服务地址
dubbo.protocol.port=20880 //<span style="color: rgb(51, 51, 51); font-family: arial; font-size: 13px; line-height: 20.02px;">用</span><span style="color: rgb(204, 0, 0); font-family: arial; font-size: 13px; line-height: 20.02px;">dubbo</span><span style="color: rgb(51, 51, 51); font-family: arial; font-size: 13px; line-height: 20.02px;">协议在20880端口暴露服务</span>
dubbo.registry.group=dev //<span style="color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Tahoma, Arial, STXihei, "Microsoft YaHei", 微软雅黑, sans-serif; font-size: 16px; line-height: 27.2px; background-color: rgb(254, 254, 254);">设置zookeeper的根节点,不设置将使用无根树。</span>
4、spring配置文件applicationContext配置
<!-- 使用zookeeper注册中心暴露服务地址 -->
<dubbo:registry address="${dubbo.registry.zookeeper.address}" />
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="${dubbo.application.name}" />
<dubbo:protocol name="dubbo" port="${dubbo.protocol.port}" />
<span style="white-space:pre"> </span><dubbo:service interface="com.midea.jr.pic.picture.service.PictureService" ref="pictureService" version="1.0.0"/>//注册服务
5、服务端调用 spring配置文件applicationContext配置
<span style="font-family:Verdana, Arial, Helvetica, sans-serif;"><dubbo:reference id="pictureService" interface="com.midea.finance.framework.identity.service.pictureService" version="1.0.0" /></span>
6、dubbo服务监控可以使用 dubbo monitor,监控服务提供及消费