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 风格 ...
随机推荐
- Oracle-检查原因并重新编译无效的存储过程
1.查看存储过程编译无效的原因 show errors procedure hr.getperson; 2.指定一个存储过程进行编译 alter procedure hr.getperson com ...
- mysql 导入时报错:Got a packet bigger than‘max_allowed_packet’bytes
原因是max_allowed_packet 值设置过小. 网上粘贴一段定义: max_allowed_packet:指代mysql服务器端和客户端在一次传送数据包的过程当中数据包的大小这个是定义mys ...
- opencv3.2.0实现视频抽帧,并保存成图片
.实现指定帧数的抽取.和全部帧数的抽取,并保存到指定目录. 在QT新建一个控制台程序,程序源码如下:(程序实现每十帧获取一次帧) #include <QCoreApplication> # ...
- 解决提交项目到GitHub,报错Please tell me who you are的问题
描述: 在第一次提交项目到GitHub时,出现了以下问题 看了一下错误原因:Run git config --global user.email "you@example.com" ...
- java里 equals和== 区别
1.java中equals和==的区别 值类型是存储在内存中的堆栈(简称栈),而引用类型的变量在栈中仅仅是存储引用类型变量的地址,而其本身则存储在堆中.2.==操作比较的是两个变量的值是否相等,对于引 ...
- onInterceptTouchEvent与onTouchEvent默认返回值
其中Layout里的onInterceptTouchEvent默认返回值是false,这样touch事件会传递到View控件,Layout里的onTouch默认返回值是false, View里的onT ...
- java 内存分析之this
package Demo; /** * this 的值是当前对象的引用 * @author Aaron * */ public class Boy { private int age; public ...
- ExtJs 4.1.1 文件结构解析
- jsp到java后台中文乱码问题
---首先描述一下我的情况,我的jsp 设置了编码格式 <%@ page language="java" contentType="text/html; ch ...
- 关于p标签
说p标签是不能嵌套div和p的,嵌套会被浏览器解析分离.但如果你使用了document.createElement创建div,再appendChild的话反而可以了.看来浏览器并不支持动态解析