spring boot集成dubbo
spring-boot-start-dubbo
spring-boot-start-dubbo,让你可以使用spring-boot的方式开发dubbo程序。使dubbo开发变得如此简单。
如何使用
1. clone 代码(可选,已经发布到中央仓库,可以直接依赖中央仓库的稳定版本)
git clone git@github.com:teaey/spring-boot-starter-dubbo.git
2. 编译安装(可选)
cd spring-boot-starter-dubbo
mvn clean install
3. 修改maven配置文件(可以参考样例spring-boot-starter-dubbo-sample)
- 在Spring Boot项目的pom.xml增加parent:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
</parent>
- 在Spring Boot项目的pom.xml中添加以下依赖:
根据实际情况依赖最新版本
<dependency>
<groupId>io.dubbo.springboot</groupId>
<artifactId>spring-boot-starter-dubbo</artifactId>
<version>1.0.0</version>
</dependency>
- maven插件用于打包成可执行的uber-jar文件,添加以下插件(这里一定要加载需要打包成jar的mudule的pom中)
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.3.6.RELEASE</version>
</plugin>
4. 发布服务
服务接口:
package cn.teaey.sprintboot.test;
public interface EchoService {
String echo(String str);
}
在application.properties添加Dubbo的版本信息和客户端超时信息,如下:
spring.dubbo.application.name=provider
spring.dubbo.registry.address=zookeeper://192.168.99.100:32770
spring.dubbo.protocol.name=dubbo
spring.dubbo.protocol.port=20880
spring.dubbo.scan=cn.teaey.sprintboot.test
在Spring Application的application.properties中添加spring.dubbo.scan即可支持Dubbo服务发布,其中scan表示要扫描的package目录
- spring boot启动
package cn.teaey.sprintboot.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Server {
public static void main(String[] args) {
SpringApplication.run(Server.class, args);
}
}
- 编写你的Dubbo服务,只需要添加要发布的服务实现上添加 @Service ,如下
package cn.teaey.sprintboot.test;
import com.alibaba.dubbo.config.annotation.Service;
@Service(version = "1.0.0")
public class EchoServerImpl implements EchoService {
public String echo(String str) {
System.out.println(str);
return str;
}
}
5. 消费Dubbo服务
- 在application.properties添加Dubbo的版本信息和客户端超时信息,如下:
spring.dubbo.application.name=consumer
spring.dubbo.registry.address=zookeeper://192.168.99.100:32770
spring.dubbo.scan=cn.teaey.sprintboot.test
在Spring Application的application.properties中添加spring.dubbo.scan即可支持Dubbo服务发布,其中scan表示要扫描的package目录
- spring boot启动
package cn.teaey.sprintboot.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication
public class Client {
public static void main(String[] args) {
ConfigurableApplicationContext run = SpringApplication.run(Client.class, args);
AbcService bean = run.getBean(AbcService.class);
System.out.println(bean.echoService.echo("abccc"));
}
}
- 引用Dubbo服务,只需要添加要发布的服务实现上添加 @Reference ,如下:
package cn.teaey.sprintboot.test;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;
@Component
public class AbcService {
@Reference(version = "1.0.0")
public EchoService echoService;
}
6. 打包
可以直接执行Server或者Client启动
可以通过mvn clean package 打包成可执行的uber-jar文件
spring boot集成dubbo的更多相关文章
- 玩转Spring Boot 集成Dubbo
玩转Spring Boot 集成Dubbo 使用Spring Boot 与Dubbo集成,这里我之前尝试了使用注解的方式,简单的使用注解注册服务其实是没有问题的,但是当你涉及到使用注解的时候在服务里面 ...
- Spring boot 集成 Dubbo 快速搭建
架构: 1.ZooKeeper:服务注册中心 2.api工程:提供对外暴露的服务API 3.provider:服务提供者 4.consumer:服务消费者 示例如下: (一)新建 Maven 项目 a ...
- Spring boot 集成Dubbo简单版,准备工作,
一.GitHub上找寻Dubbo资源 阿里巴巴在其GitHub上已经写好一个Github案例所以我们只要进入其Git上就可以看到和clone这个项目 二.阿里巴巴GitHub使用 https://gi ...
- 一个spring boot集成dubbo的小例子
请移步github,介绍和代码均在上面了:https://github.com/wuxun1997/voicebox 这里再多说两句.github上的这个小例子默认使用组播作为注册中心,你也可以把组播 ...
- spring boot 集成 zookeeper 搭建微服务架构
PRC原理 RPC 远程过程调用(Remote Procedure Call) 一般用来实现部署在不同机器上的系统之间的方法调用,使得程序能够像访问本地系统资源一样,通过网络传输去访问远程系统资源,R ...
- Spring boot集成RabbitMQ(山东数漫江湖)
RabbitMQ简介 RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统 MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出 ...
- Spring boot 集成Dubbox(山东数漫江湖)
前言 因为工作原因,需要在项目中集成dubbo,所以去查询dubbo相关文档,发现dubbo目前已经不更新了,所以把目光投向了dubbox,dubbox是当当网基于dubbo二次开发的一个项目,dub ...
- Spring Boot集成Jasypt安全框架
Jasypt安全框架提供了Spring的集成,主要是实现 PlaceholderConfigurerSupport类或者其子类. 在Sring 3.1之后,则推荐使用PropertySourcesPl ...
- Spring boot集成swagger2
一.Swagger2是什么? Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件. Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格 ...
随机推荐
- MySQL的数据控制语言DCL
我们使用DDL的"CREATE USER"语句创建用户,新的SQL用户不允许访问属于其他SQL用户的表,也不能立即创建自己的表,它必须被授权.可以授予的权限包括以下几组: 1.列权 ...
- Code Signal_练习题_shapeArea
A 1-interesting polygon is just a square with a side of length 1. An n-interesting polygon is obtain ...
- package.json中devDependencies与dependencies的区别
前言:之前一直不懂既然都是项目的依赖,为什么要分成两个部分,devDependencies和dependencies,有什么区别? 安装方式 我们在通过npm安装插件或库时,有三种方式: npm in ...
- less之旅
在遇到less之前,一直和css交往,当less出现在我码农生涯的时候,被她给深深地吸引.从此,less成了自己码农生活里面的一房,css退居二房!那么,less到底有什么魅力让我如此迷上她呢? le ...
- USTCCourseCommunity 项目介绍
我们的项目名为USTCCourseCommunity,科大课程社区,主要提供课表管理.课程资源管理.课程信息管理.智能排课.轻松评课等方面的服务,旨在为科大师生提供便捷. 科大现有课程服务形式存在的问 ...
- Jmeter入门--关联
名称解释 关联是请求与请求之间存在数据依赖关系,需要从上一个请求获取下一个请求需要回传回去的数据. 具体方法 Jmeter关联有两种方法:Xpath.正则表达式 方法一:Xpath主要用于响应是格式是 ...
- 用华为eNSP模拟器配置Hybrid、Trunk和Access三种链路类型端口
上一篇文章写到三层交换机实现多个VLAN之间互相通讯,有朋友提问要如何进行配置,可有案例分析.其实那天我在写的时候也有做过模拟,只是后来没有保存.今天重新模拟一次,并附上详细配置命令,希望能够帮助到大 ...
- WinForm 应用程序禁止多个进程运行
方法一: 禁止多个进程运行 using System; using System.Collections.Generic; using System.Linq; using System.Window ...
- ext button 属性
var buttonName = new Ext.Button({ id:"buttonName", text:" ...
- Allure 安装及使用
linux下安装方法 Allure requires Java 8 or higher npm install -g allure-commandline --save-dev (如果npm不能 ...