简介

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. 开源数字人直播DH_live web整合包免训练使用教程

    资源导航首页 项目地址 基于开源项目:DH_live做的web交互系统 主要实现:免训练数字人视频制作和实时语音数字人 可搭配一些直播场控软件的语音 驱动数字人进行直播     整合包下载 「数字人( ...

  2. AOP-Redis缓存

    我没有单独使用过Redis,细节我可能解释不到位.该文章是采用依赖注入实现AOP-Redis缓存功能的 . 之前有写实现Memory缓存的.异曲同工之妙. 使用Redis离不开安装get包:Stack ...

  3. Ubuntu系统查看文件夹目录

    方法1: 进入文件夹里面我们可以使用 按下Ctrl + L 可以看到文件的路径了 然后复制即可. 方法2: 可以鼠标右键点击最下面的属性,然后复制位置里面的路径即可

  4. Cesium 在线地图访问总结

    参考:https://deyihu.github.io/src/maptalks-tileLayercollection/examples/?tdsourcetag=s_pcqq_aiomsg 以下u ...

  5. 基于Vue的前后段分离开发项目中<img :src />标签中引用vue的data属性中定义的图像地址失败的解决办法

    问题描述: 基于Vue的前后段分离开发项目中<img  :src />标签中引用vue的data属性中定义的图像地址失败,如下图所示: 解决办法: 修改后写法,加上require即可.如下 ...

  6. 2020年了,Android后台保活还有戏吗?看我如何优雅的实现!

    1.引言 对于移动端IM应用和消息推送应用的开发者来说,Android后台保活这件事是再熟悉不过了. 自从Android P(即Android 8.0)出现以后,Android已经从系统层面将后台保活 ...

  7. Linux安装配置Go语言

    Linux安装配置Go语言 官网:https://go.dev/dl/ 从官网下载,选择linux下载压缩包. sudo cp -r go/ /usr/local sudo gedit /etc/pr ...

  8. Windows Terminal 智能提示

    安装PSReadLine Install-Module -Name PSReadLine -AllowClobber -Force 打开$profile notepad $profile 配置补全 在 ...

  9. map循环如何跳出循环

    今天在开发的时候遇到了一个问题.就是想在使用map的时候跳出循环无法实现,于是就在网上搜寻了一番,说map本身不能跳出循环,有一个大佬提出了抛出异常的方法,记录一下 let list=[1,2,3,4 ...

  10. WPF 背景阴影窗体

    <Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/200 ...