简介

Dubbox是当当网对阿里的Dubbo进行增强的一个分支。在使用springboot之后,我们发现很多配置并不一定要使用xml。这篇文章的目的是让你使用Dubbox时能像使用springboot的其它功能一样可以在application.properties中配置。

基础整合

  1. 进入https://github.com/dangdangdotcom/dubbox ,将源码下载(当当网没有提交上maven仓库,所以不能直接从中央仓库依赖);打包进本地仓库
mvn clean install -DskipTests
  1. 添加Maven依赖
		<!-- zookeeper -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<!-- Dubbox -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.8.4</version>
</dependency>
<!-- springboot的注解处理器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
  1. 添加配置类
	@Configuration
public class DubboConfig { @Bean
@ConfigurationProperties(prefix="dubbo.application")
public ApplicationConfig applicationConfig() {
ApplicationConfig applicationConfig = new ApplicationConfig();
return applicationConfig;
} @Bean
@ConfigurationProperties(prefix="dubbo.registry")
public RegistryConfig registryConfig() {
RegistryConfig registryConfig = new RegistryConfig();
return registryConfig;
} @Bean
@ConfigurationProperties(prefix="dubbo.annotation")
public AnnotationBean annotationBean() {
AnnotationBean annotationBean = new AnnotationBean();
return annotationBean;
} @Bean
@ConfigurationProperties(prefix="dubbo.protocol")
public ProtocolConfig protocolConfig() {
ProtocolConfig protocolConfig = new ProtocolConfig();
return protocolConfig;
}
}
  1. 在application.properties中配置Dubbox属性
	#应用名
dubbo.application.name=
#负责人
dubbo.application.owner=
#注册zookeeper的地址
dubbo.registry.address=zookeeper://localhost:2181
#扫包
dubbo.annotation.package=com.yeauty.service
#协议 (有 dubbo、rest、http、hessian、webservice)
dubbo.protocol.name=dubbo
#协议暴露服务的端口(Integer类型)
dubbo.protocol.port=20880
  1. 提供者与消费者
	提供者注解(实现类上):
@Service(包:com.alibaba.dubbo.config.annotation.Service)
@Component(包:org.springframework.stereotype.Component) 消费者注解(Interface上):
@Reference(包:com.alibaba.dubbo.config.annotation.Reference)
  1. 注意!!!

    springboot的开发热部署包一定要去掉!不然会出BUG
		<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
现在已经可以正常使用了,若想进行扩展,可以继续往下~

指定序列化配置

  1. 添加Maven依赖
		<dependency>
<groupId>com.esotericsoftware.kryo</groupId>
<artifactId>kryo</artifactId>
<version>2.24.0</version>
</dependency>
<dependency>
<groupId>de.javakaffee</groupId>
<artifactId>kryo-serializers</artifactId>
<version>0.26</version>
</dependency>
  1. application.properties中配置属性
	#序列化方式(kryo是目前效率最高的)
dubbo.protocol.serialization=kryo
#序列化优化的实现类
dubbo.protocol.optimizer=
  1. 添加序列化实现类
	public class SerializationOptimizerImpl implements SerializationOptimizer {

	    public Collection<Class> getSerializableClasses() {
List<Class> classes = new LinkedList<Class>(); return classes;
}
}

需要进行kryo序列化的类在这里add进list里面

详细可参考:https://dangdangdotcom.github.io/dubbox/serialization.html

Dubbox的REST支持

  1. 添加Maven依赖
		<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.7.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.7.Final</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<!-- 如果要使用json序列化 -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>3.0.7.Final</version>
</dependency>
<!-- 如果要使用xml序列化 -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.0.7.Final</version>
</dependency>
  1. 在配置类中添加方法
	@Bean
@ConfigurationProperties(prefix="dubbo.protocol.rest")
public ProtocolConfig protocolRestConfig() {
ProtocolConfig protocolConfig = new ProtocolConfig();
return protocolConfig;
}
  1. application.properties中配置属性
	dubbo.protocol.rest.name=rest
dubbo.protocol.rest.port=8082
dubbo.protocol.rest.server=tomcat

更多属性配置和使用方法请参考:https://dangdangdotcom.github.io/dubbox/rest.html

未经同意不得转载

SpringBoot整合Dubbox(无XML配置)的更多相关文章

  1. SpringBoot 整合 Mybatis + Mysql——XML配置方式

    一.介绍 SpringBoot有两种方法与数据库建立连接,一种是集成Mybatis,另一种用JdbcTemplate,本文主要讨论集成Mybatis方式. SpringBoot整合Mybatis也有两 ...

  2. SpringBoot整合MyBatis之xml配置

    现在业界比较流行的数据操作层框架 MyBatis,下面就讲解下 Springboot 如何整合 MyBatis,这里使用的是xml配置SQL而不是用注解.主要是 SQL 和业务代码应该隔离,方便和 D ...

  3. SpringBoot系列-整合Mybatis(XML配置方式)

    目录 一.什么是 MyBatis? 二.整合方式 三.实战 四.测试 本文介绍下SpringBoot整合Mybatis(XML配置方式)的过程. 一.什么是 MyBatis? MyBatis 是一款优 ...

  4. SpringBoot整合log4j2进行日志配置及防坑指南

    写在前面 最近项目经理要求将原先项目中的日志配置logBack,修改为log4j2,据说是log4j2性能更优于logback,具体快多少,网上有说快10多倍,看来还是很快的,于是新的一波挑战又开始了 ...

  5. 【Springboot】Springboot整合Jasypt,让配置信息安全最优雅方便的方式

    1 简介 在上一篇文章中,介绍了Jasypt及其用法,具体细节可以查看[Java库]如何使用优秀的加密库Jasypt来保护你的敏感信息?.如此利器,用之得当,那将事半功倍.本文将介绍Springboo ...

  6. MongoDB和Java(4):Spring Data整合MongoDB(XML配置)

    最近花了一些时间学习了下MongoDB数据库,感觉还是比较全面系统的,涉及了软件安装.客户端操作.安全认证.副本集和分布式集群搭建,以及使用Spring Data连接MongoDB进行数据操作,收获很 ...

  7. SpringBoot无XML配置

    SpringBoot,自己研究了好几天,以前也是没有接触过这类的框架,不过原理吧,也就是那么些个原理,毕竟都是Spring开源下的子框架. 好了,回归正题,今天晚上研究了好久,写出来了无配置文件的ja ...

  8. SpringBoot整合Mybatis之xml

    SpringBoot整合Mybatis mybatis ORM框架.几个重要的概念: Mapper配置 : 可以使用基于XML的Mapper配置文件来实现,也可以使用基于Java注解的Mybatis注 ...

  9. 【转】SpringBoot学习笔记(7) SpringBoot整合Dubbo(使用yml配置)

    http://blog.csdn.net/a67474506/article/details/61640548 Dubbo是什么东西我这里就不详细介绍了,自己可以去谷歌 SpringBoot整合Dub ...

  10. ssm整合(基于xml配置方式)

    本文是基于xml配置的方式来整合SpringMVC.Spring和Mybatis(基于注解的方式会再写一篇文章),步骤如下: (1)首先自然是依赖包的配置文件 pom.xml <project ...

随机推荐

  1. Sublime Text 4143 激活码

    1 .Windows激活方法 安装地址:Download - Sublime Text 使用浏览器打开hexed.it(https://hexed.it/) 点击"打开文件",选择 ...

  2. Qt数据库应用17-通用数据库请求

    一.前言 数据库请求是在数据库采集的基础上,换成http请求的形式来获取数据,这样就脱离了数据库组件,而采用的通用的http请求的形式从数据库拿数据库,这个通用性就非常广泛了,比如对方用java采集到 ...

  3. Windows10 64环境下用Qt5.12.12自带的mingw730_64构建编译OpenCV4.1.0时cmake-3.20.6中的参数配置

    一.环境条件说明: 操作系统:Windows10 64环境 编译工具:用Qt5.12.12自带的mingw730_64构建 构建对象:编译OpenCV4.1.0的Release 64位和Debug 6 ...

  4. findHomography()函数详解

    indHomography: 计算多个二维点对之间的最优单映射变换矩阵 H(3行x3列) ,使用最小均方误差或者RANSAC方法 函数功能:找到两个平面之间的转换矩阵. Mat cv::findHom ...

  5. Awesome-Text2GQL:图查询微调语料的自动生成框架

      过去一年,GraphRAG技术发展如火如荼,尤其是基于关键词.向量驱动的知识检索方法不胜枚举.然而通过子图召回的检索方式,对用户真实查询意图的定位仍缺乏足够的准确度.我们需要更直接的方式,将自然语 ...

  6. Solution Set - 冬日纪行(前半)

    目录 0.「集训队互测 2018」「LOJ #2504」小 H 爱染色 ✡️ 1.「LOJ #6402」yww 与校门外的树 2.「集训队互测 2019」「LOJ #3075」组合数求和 ✡️ 3.「 ...

  7. CDS标准视图:一次性账户的客户行项目 I_ONETIMEACCOUNTCUSTOMER

    视图名称:一次性账户的客户行项目 视图类型:基础 视图代码: 点击查看代码 @EndUserText.label: 'One-Time Account Data for Customer Items' ...

  8. [rustGUI][iced]基于rust的GUI库iced(0.13)的部件学习(05):svg图片转为png格式(暨svg部件的使用)

    前言 本文是关于iced库的部件介绍,iced库是基于rust的GUI库,作者自述是受Elm启发. iced目前的版本是0.13.1,相较于此前的0.12版本,有较大改动. 本合集是基于新版本的关于分 ...

  9. MongoDB:分页查询(统计查询和分页列表查询)、排序查询、正则的复杂条件查询、比较查询、包含查询、条件连接查询

  10. 如何安全发布 CompletableFuture ?Java9新增方法分析

    如何安全发布 CompletableFuture ?Java9新增方法分析 本文未经允许禁止转载. JDK9 中对于CompletableFuture做了新的增强,除了超时功能(orTimeout), ...