说明

目前互联网公司,大部分项目都是基于分布式,一个项目被拆分成几个小项目,这些小项目会分别部署在不同的计算机上面,这个叫做微服务。当一台计算机的程序需要调用另一台计算机代码的时候,就涉及远程调用。此时dubbo就粉末登场了。

搭建工程

idea新建工程后,删除src文件夹,然后在gradle文件中输入

buildscript {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.21.RELEASE'
}
} plugins {
id 'java'
}
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
group 'com.demoMuty'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8 repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
mavenCentral()
} dependencies {
compile 'org.springframework.boot:spring-boot-starter-mail'
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.4'
compile 'com.alibaba.boot:dubbo-spring-boot-starter:0.1.0'
compile 'com.101tec:zkclient:0.10'
// developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtime 'mysql:mysql-connector-java'
compile("com.baomidou:mybatis-plus-boot-starter:3.1.0")
compile("com.baomidou:mybatis-plus-generator:3.1.1")
compileOnly 'org.projectlombok:lombok'
testCompile 'org.springframework.boot:spring-boot-starter-test'
}

如图所示



boolean作为父工程,然后再见三个模块

booleanone作为父模块 booleanteo作为服务者模块 booleanthree作为消费者模块

添加dubbo.xml

然后在每个模块新建com.test包,在包下新建启动类

@SpringBootApplication
public class BaseApplication extends SpringBootServletInitializer {
}

然后在每个模块的gradle文件中引入上面的依赖,然后在消费者模块和生产者模块的依赖中加入父模块依赖,如图

然后在booleantwo的生产者模块的resource资源文件中加入dubbo文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
"> <!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="hello-world-app"/> <!-- 使用multicast广播注册中心暴露服务地址 -->
<dubbo:registry address="zookeeper://localhost:2181"/> <!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880"/> <!-- 声明需要暴露的服务接口 -->
<dubbo:service
interface="com.test1.provider.DemoService"
ref="demoService"
group="hello-world-app"
version="1.0.0"
/>
</beans>

在启动类中加入注解

@ImportResource({"classpath:dubbo.xml"})

然后在booleantwo的消费者模块的resource资源文件中加入dubbo文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
"> <!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="hello-world-app"/> <!-- 使用multicast广播注册中心暴露服务地址 -->
<dubbo:registry address="zookeeper://localhost:2181"/> <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:reference
interface="com.test1.provider.DemoService"
group="hello-world-app"
version="1.0.0"
id="demoService"/>
</beans>

在启动类中加入注解

@ImportResource({"classpath:dubbo.xml"})

编写dubbo代码

在父模块中写dubbo接口

package com.test1.provider;

/**
* @author buer
* create 2019/7/2 22:13
* description
*/
public interface DemoService {
String sayHello(String name);
}

然后在生产者模块中写dubbo实现类

package com.test1.dubbo;

import com.test1.provider.DemoService;
import org.springframework.stereotype.Service; /**
* @author buer
* create 2019/7/2 22:14
* description
*/
@Service("demoService")
public class DemoServiceImpl implements DemoService {
@Override
public String sayHello(String name) {
return "hello,dubbo"+name;
}
}

然后在消费者模块中写dubbo调用


package com.test1.controller; import com.test1.provider.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; /**
* @author boolean
* Date: 2019/7/2 19:48
* description:
*/
@RestController
public class he {
@Autowired
private DemoService demoService; @RequestMapping("/he")
public String hello(){
return "he";
} @RequestMapping("/chen")
public String hello1(){
return demoService.sayHello("chen");
}
}

启动

最后添加war包



打开zkServer.cmd



启动信息



如果启动有乱码的话

回到idea软件 打开tomcat的设置 找到VM options:,然后输入

-Dfile.encoding=UTF-8

测试



代码地址:

https://github.com/blackdogss/HelloWorld.git

公众号

dubbo整合springboot最详细入门教程的更多相关文章

  1. gulp详细入门教程

    本文链接:http://www.ydcss.com/archives/18 gulp详细入门教程 简介: gulp是前端开发过程中对代码进行构建的工具,是自动化项目的构建利器:她不仅能对网站资源进行优 ...

  2. ant使用指南详细入门教程

    这篇文章主要介绍了ant使用指南详细入门教程,本文详细的讲解了安装.验证安装.使用方法.使用实例.ant命令等内容,需要的朋友可以参考下 一.概述 ant 是一个将软件编译.测试.部署等步骤联系在一起 ...

  3. gulp详细入门教程(转载)

    本文转载自: gulp详细入门教程

  4. <转载>ant使用指南详细入门教程 http://www.jb51.net/article/67041.htm

    这篇文章主要介绍了ant使用指南详细入门教程,本文详细的讲解了安装.验证安装.使用方法.使用实例.ant命令等内容,需要的朋友可以参考下 一.概述 ant 是一个将软件编译.测试.部署等步骤联系在一起 ...

  5. Docker最详细入门教程

    Docker原理.详细入门教程 https://blog.csdn.net/deng624796905/article/details/86493330 阮一峰Docker入门讲解 http://ww ...

  6. Dubbo整合Springboot框架

    本文使用的是alibaba的Dubbo. Dubbo整合Springboot可以分为四步: 第一步:首先需要了解Dubbo官方给的建议,至少有三个工程: 接口工程:主要存实体bean和业务接口 服务提 ...

  7. Kibana详细入门教程

    Kibana详细入门教程   目录 一.Kibana是什么 二.如何安装 三.如何加载自定义索引 四.如何搜索数据 五.如何切换中文 六.如何使用控制台 七.如何使用可视化 八.如何使用仪表盘 一.K ...

  8. dubbo入门学习(三)-----dubbo整合springboot

    springboot节省了大量的精力去配置各种bean,因此通过一个简单的demo来整合springboot与dubbo 一.创建boot-user-service-provider 本篇博文基于上篇 ...

  9. Duboo整合SpringBoot超级详细例子(附源码)

    dubbo3.0整合SpringBoot例子 dubbo新版本(3.0以上)在相对于 dubbo 旧版本(2.5.2.6.2.7),有很多的不相同的地方. 官方文档也说了新版本的特性: https:/ ...

随机推荐

  1. Python实例讲解 -- 获取本地时间日期(日期计算)

    1. 显示当前日期: print time.strftime('%Y-%m-%d %A %X %Z',time.localtime(time.time())) 或者 你也可以用: print list ...

  2. RTB业务知识2-Open-RTB全景

    一个.前言 openrtb这是一套开源的竞价广告系统,来自IAB贡献,井. 有许多值太借鉴,提供sdk api接口文档介绍,整理了相关的资料.主要包含其生态图体系.业务流程和基本的对象模型和数据模型. ...

  3. MIPS之路在何方?

    目前市场上还有谁想要MIPS?MIPS接下来将何去何从?如果有一家公司希望能好好地经营MIPS,应该用什么策略呢?   MIPS仍然有营收来源.它还拥有ARM所没有的多执行绪技术.有人说,只要想到半导 ...

  4. theano 安装杂记

    0. MinGW MinGW:Windows 下的 g++等linux 下的编译工具: Anaconda 下 MinGW 的安装(进行 windows cmd 界面):conda install mi ...

  5. WPF3D绘图的基础

    原文:WPF3D绘图的基础 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/m0_37591671/article/details/69487096 ...

  6. WPF loading加载动画库

    原文:WPF loading加载动画库 1. 下载Dll        https://pan.baidu.com/s/1wKgv5_Q8phWo5CrXWlB9dA 2.在项目中添加引用       ...

  7. OpenGL(十五) OpenCV+OpenGL实现水面倒影

    有两幅原始图片,一个是景物图像,一个是水面图像,尝试生成景物在水中的倒影: 在OpenGL中,加载并显示这个景物图像可以把这个图像作为纹理载入即可,把图像直接选择180度的效果就相当于是在镜面中倒影的 ...

  8. WPF 控件的内容属性

    WPF的内容属性不应定都是content, 例如TextBlock的内容属性是Text Panel的内容属性是Children ListBox的内容属性是Items

  9. 高性能mysql笔记 第一章 mysql架构

    1.1  mysql逻辑结构 第一层: 负责连接处理,授权认证,安全等事情 第二层:负责mysql的大部分核心功能 ,查询解析,分析,优化,缓存和所有的内置函数,所有跨存储引擎的功能都在这一层实现,, ...

  10. 线性渐变、辐射渐变、角度渐变-QLinearGradient,QRadialGradient,QConicalGradient

    渐变,是指逐渐的,有规律性的变化,是一种规律性很强的现象.Qt提供了一个与渐变相关的QGradient类,目前支持三种渐变画刷,分别是线性渐变(QLinearGradient).辐射渐变(QRadia ...