欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

dubbo整合springboot新手入門教程詳解

 更新時間:2019年07月05日 08:28:27   作者:布爾bl  
這篇文章主要介紹了dubbo整合springboot新手入門詳解,當一臺計算機的程序需要調(diào)用另一臺計算機代碼的時候,就涉及遠程調(diào)用。此時dubbo就粉末登場了,需要的朋友可以參考下

前言

目前互聯(lián)網(wǎng)公司,大部分項目都是基于分布式,一個項目被拆分成幾個小項目,這些小項目會分別部署在不同的計算機上面,這個叫做微服務(wù)。當一臺計算機的程序需要調(diào)用另一臺計算機代碼的時候,就涉及遠程調(diào)用。此時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作為服務(wù)者模塊 booleanthree作為消費者模塊

添加dubbo.xml

然后在每個模塊新建com.test包,在包下新建啟動類

@SpringBootApplication
public class BaseApplication extends SpringBootServletInitializer {
}

然后在每個模塊的gradle文件中引入上面的依賴,然后在消費者模塊和生產(chǎn)者模塊的依賴中加入父模塊依賴,如圖

然后在booleantwo的生產(chǎn)者模塊的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
    ">

  <!-- 提供方應(yīng)用信息,用于計算依賴關(guān)系 -->
  <dubbo:application name="hello-world-app"/>

  <!-- 使用multicast廣播注冊中心暴露服務(wù)地址 -->
  <dubbo:registry address="zookeeper://localhost:2181"/>

  <!-- 用dubbo協(xié)議在20880端口暴露服務(wù) -->
  <dubbo:protocol name="dubbo" port="20880"/>

  <!-- 聲明需要暴露的服務(wù)接口 -->
  <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
    ">

<!-- 提供方應(yīng)用信息,用于計算依賴關(guān)系 -->
<dubbo:application name="hello-world-app"/>

<!-- 使用multicast廣播注冊中心暴露服務(wù)地址 -->
<dubbo:registry address="zookeeper://localhost:2181"/>

<!-- 生成遠程服務(wù)代理,可以和本地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);
}

然后在生產(chǎn)者模塊中寫dubbo實現(xiàn)類

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調(diào)用

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的設(shè)置 找到VM options:,然后輸入

-Dfile.encoding=UTF-8

測試


代碼地址:

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java實用工具之StringJoiner詳解

    Java實用工具之StringJoiner詳解

    這篇文章主要介紹了Java實用工具之StringJoiner詳解,文中有非常詳細的代碼示例,對正在學(xué)習(xí)java的小伙伴們有很好地幫助,需要的朋友可以參考下
    2021-05-05
  • 探討:使用httpClient在客戶端與服務(wù)器端傳輸對象參數(shù)的詳解

    探討:使用httpClient在客戶端與服務(wù)器端傳輸對象參數(shù)的詳解

    本篇文章是對使用httpClient在客戶端與服務(wù)器端傳輸對象參數(shù)進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06
  • SpringBoot中Zookeeper分布式鎖的原理和用法詳解

    SpringBoot中Zookeeper分布式鎖的原理和用法詳解

    Zookeeper是一個分布式協(xié)調(diào)服務(wù),它提供了高可用、高性能、可擴展的分布式鎖機制,SpringBoot是一個基于Spring框架的開發(fā)框架,它提供了對Zookeeper分布式鎖的集成支持,本文將介紹SpringBoot中的 Zookeeper分布式鎖的原理和使用方法,需要的朋友可以參考下
    2023-07-07
  • 一文帶你搞懂Java單例模式

    一文帶你搞懂Java單例模式

    單例就是單實例的意思,即在系統(tǒng)全局,一個類只創(chuàng)建一個對象,并且在系統(tǒng)全局都可以訪問這個對象而不用重新創(chuàng)建。本文將通過示例為大家詳細講解Java單例模式的使用,需要的可以參考一下
    2022-11-11
  • Spring實現(xiàn)上拉刷新和下拉加載效果

    Spring實現(xiàn)上拉刷新和下拉加載效果

    這篇文章主要為大家詳細介紹了Spring實現(xiàn)上拉刷新和下拉加載效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • 解析MyBatisPlus解決邏輯刪除與唯一索引的兼容問題

    解析MyBatisPlus解決邏輯刪除與唯一索引的兼容問題

    這篇文章主要介紹了MyBatisPlus解決邏輯刪除與唯一索引的兼容問題,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-04-04
  • java中List分頁的幾種方法介紹

    java中List分頁的幾種方法介紹

    大家好,本篇文章主要講的是java中List分頁的幾種方法介紹,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • 給JavaBean賦默認值并且轉(zhuǎn)Json字符串的實例

    給JavaBean賦默認值并且轉(zhuǎn)Json字符串的實例

    這篇文章主要介紹了給JavaBean賦默認值并且轉(zhuǎn)Json字符串的實例,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • SpringMVC訪問controller報錯404的解決辦法(總結(jié)超詳細)

    SpringMVC訪問controller報錯404的解決辦法(總結(jié)超詳細)

    純注解配置SpringMVC程序,使用tomcat8.5.95版本啟動,能啟動成功并且訪問index.jsp頁面,但是訪問/save時出現(xiàn)404無法訪問,本文給大家介紹了SpringMVC訪問controller報錯404的解決辦法,文章總結(jié)的非常詳細,需要的朋友可以參考下
    2024-05-05
  • Java實現(xiàn)平鋪列表(List)互轉(zhuǎn)樹形(Tree)結(jié)構(gòu)

    Java實現(xiàn)平鋪列表(List)互轉(zhuǎn)樹形(Tree)結(jié)構(gòu)

    本文主要介紹了Java實現(xiàn)平鋪列表(List)互轉(zhuǎn)樹形(Tree)結(jié)構(gòu),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08

最新評論