springboot2.x纯注解整合dubbo
springboot1.x和springboot2.x整合差距挺大的,基于最新的2.x进行整合,使用纯注解的方式
依赖选取
首先pom文件的依赖引入,maven仓库有Apache和alibaba两个

Dubbo早已孵化完成,破壳而出,成为Apache顶级项目,这里引用Apache的maven依赖
框架搭建
采用maven聚合项目,架构如图所示

详细层级结构图

api 公用的entity和service接口
provider-log log服务提供方
provider-message message服务提供方
consumer 消费方
引入依赖
顶级pom.xml引入spring-boot-starter-parent,使用新版2.1.6.release
三个聚合模块
<modules>
<module>api</module>
<module>provider-log</module>
<module>provider-message</module>
</modules> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> </dependencies>
api模块用于提供dubbo服务接口,所以将dubbo的依赖添加在api里面,是有些不妥
api->pom.xml
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>2.7.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
<type>pom</type>
</dependency>
其余的三个工程,都是引入父工程,依赖引入api,spring-boot-starter-web可选,提供web服务的话加上,不提供服务可以不加
<parent>
<groupId>com.chy.wx</groupId>
<artifactId>spring-boot-dubbo</artifactId>
<version>1.0-SNAPSHOT</version>
</parent> <dependencies> <dependency>
<groupId>com.chy.wx</groupId>
<artifactId>sea-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependencies>
api添加两个entity和两个service,更有区分性

配置文件
两个提供者provider,为的是更有区分性,application配置,这里采用yuml语法。
跟springboot1.x的区别是,dubbo单独开头,前面并没有spring
server:
port: dubbo:
application:
name: sea-provider-log
registry:
protocol: zookeeper
address: 192.168.1.222:
protocol:
name: dubbo
port:
version: 1.0.
scan:
base-packages: com.log
参数说明
- dubbo.application.name 给provider起的名称
- dubbo.registry.address 表示注册的地址,不一定非得是zookeeper
- dubbo.protocol.name 就是dubbo
- dubbo.protocol.port 是注册的端口号,多个提供者使用的port需要区分开来
- dubbo.protocol.scan 是表示扫描哪些包下面的服务
- version是自定的一个版本属性
发布的服务通过@Service注解,加载被扫描的实现类上面,这里使用的是dubbo的注解

启动类上面添加@EnableDubbo注解

测试发布
命令操作查看
通过如下命令进入dubbo
telnet 192.168.1.222 21880
查看发布的服务使用ls
如下表示ErrorLogService发布成功,且版本为1.0.0

更多命令查看Telnet 命令参考手册
web服务查看
感觉不直观可以下载dubbo-admin监控工程,配置application.xml,之后启动查看
release版本 https://github.com/apache/dubbo/releases 下载运行即可
或者下载我已经上传的dubbo-admin.war包(博客园上传限制为10M)
百度云
链接:https://pan.baidu.com/s/18QSZLySLj8az11ebQJvG1Q
提取码:2jgy
CSDN
觉得慢快速下载地址:https://download.csdn.net/download/qq_37933127/10569470
将war包放入tomcat的webapps目录下,启动会自动解压
之后将application.xml修改成自己的zookeeper地址即可

默认用户名和密码都为root
启动访问即可,默认的根路径为文件夹的名字,访问如图所示即可以看详细信息

web调用方使用@Reference注解即可,如果提供了版本号需要加版本号,如下所示

完整的dubbo-demo
仅需要修改yml的zookeeper地址即可
https://github.com/chywx/spring-boot-dubbo

springboot2.x纯注解整合dubbo的更多相关文章
- Spring+MyBatis纯注解零XML整合(4)
不得不说,利用XML作为配置文件是一个非常好的想法,它可以轻松地实现配置集中化,而且修改之后无需再次编译.然而,由于大多数情况下开发者基本都会拿到程序的源码,加之对于各种XML配置文件一般情况下也只有 ...
- Dubbo学习-6-springboot整合dubbo
1.在前面帖子和工程的基础上,这里使用springboot整合dubbo,首先创建springboot项目: https://start.spring.io/ 进入spring Initializr ...
- Springboot 整合 Dubbo/ZooKeeper 详解 SOA 案例
摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢! “看看星空,会觉得自己很渺小,可能我们在宇宙中从来就是一个偶然.所以,无论什么事情,仔细想一 ...
- spring整合dubbo[单机版]
Spring整合Dubbo,这个是用xml配置的 (方式一) 来梳理下步骤: 1. 安装zookeeper,在进行简单配置[这里使用单机模式,不用集群] 2. 创建maven项目,构建项目结构 3. ...
- SpringBoot开发案例之整合Dubbo分布式服务
前言 在 SpringBoot 很火热的时候,阿里巴巴的分布式框架 Dubbo 不知是处于什么考虑,在停更N年之后终于进行维护了.在之前的微服务中,使用的是当当维护的版本 Dubbox,整合方式也是使 ...
- springboot多模块开发以及整合dubbo\zookeeper进行服务管理
之前研究了springboot单工程的使用,参考git地址:https://github.com/qiao-zhi/springboot-ssm 下面研究springboot多模块开发的过程. 1.模 ...
- springboot整合dubbo\zookeeper做注册中心
springboot整合dubbo发布服务,zookeeper做注册中心.前期的安装zookeeper以及启动zookeeper集群就不说了. dubbo-admin-2.5.4.war:dubbo服 ...
- SpringBoot2.0+Shiro+JWT 整合
SpringBoot2.0+Shiro+JWT 整合 JSON Web Token(JWT)是一个非常轻巧的规范.这个规范允许我们使用 JWT 在用户和服务器之间传递安全可靠的信息. 我们利用一定的编 ...
- java框架之SpringBoot(16)-分布式及整合Dubbo
前言 分布式应用 在分布式系统中,国内常用 Zookeeper + Dubbo 组合,而 SpringBoot 推荐使用 Spring 提供的分布式一站式解决方案 Spring + SpringBoo ...
随机推荐
- x:ArrayExtension
<Window.Resources> <x:ArrayExtension x:Key="array" Type="{x:Type sys:Int32}& ...
- EF延迟加载LazyLoading
优点 只在需要的时候加载数据,不需要预先计划,避免了各种复杂的外连接.索引.视图操作带来的低效率问题 缺陷:多次与DB交互,性能降低 阻止延迟加载解决方案:1.ToList(),返回的东西是个内存级的 ...
- DataTable转换为Entity(反射&&泛型)
public static IEnumerable<T> Parse<T>(IEnumerable<DataRow> rows) where T : class, ...
- jquery 用json设置css
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- delphi资源文件的使用
delphi资源文件的使用 资源文件(*.res)通过编译指令 $R 关联, 譬如工程文件 Project1 中的 {$R *.res} 就是关联 Project1.res 资源文件, 我们直接写作 ...
- HTML5离线缓存攻击测试(二)
经过昨天的测试,发现使用离线缓存的网站会被攻击.但是,不使用离线缓存的网站就真的不会受到这样的攻击么? 据我理解,按照标准当浏览器请求manifest文件时,若没有请求到,或者文件发生改变,应当不使用 ...
- 什么是AIFF?
AIFF是音频交换文件格式(Audio Interchange File Format)的英文缩写,是Apple公司开发的一种声音文件格式,被Macintosh平台及其应用程序所支持,Netscape ...
- DataSet与JSON互转
DataSetConverter4Delphi https://github.com/ezequieljuliano/DataSetConverter4Delphi ----------------- ...
- Codility---Dominator
Task description A zero-indexed array A consisting of N integers is given. The dominator of array A ...
- Adobe cs6 全系列软件绿色破解版-一键安装
下载地址: 链接:https://pan.baidu.com/s/1THssmSS-SnyNc2DW7Wr8cA 提取码:y3tq 软件介绍 作为全球领先的多媒体设计软件供应商,Adobe Syste ...