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

springboot2.0整合dubbo的示例代碼

 更新時間:2018年08月08日 13:40:33   作者:z七夜  
這篇文章主要介紹了springboot2.0整合dubbo的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

寫在前面:

使用springboot作為web框架,方便開發(fā)許多,做分布式開發(fā),dubbo又不可少,那么怎么整合在一起呢,

跟我學(xué)一遍,至少會用

注意,springboot2.0和springboot1.x與dubbo整合不一樣,

1.環(huán)境

1.新建一個空的maven項目,作為父工程,新建moudle,,service(接口層,及實現(xiàn)層,沒有具體分,),web(web層,springboot項目)

項目結(jié)構(gòu)如下


父pom如下

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencyManagement>
    <dependencies>


      <dependency>
        <!-- Import dependency management from Spring Boot -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.0.3.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <!--如果要把springboot工程打包成war執(zhí)行,需要該jar-->
      <!--<dependency>-->
      <!--<groupId>org.springframework.boot</groupId>-->
      <!--<artifactId>spring-boot-legacy</artifactId>-->
      <!--<version>1.0.2.RELEASE</version>-->
      <!--</dependency>-->

      <dependency>
        <groupId>com.alibaba.boot</groupId>
        <artifactId>dubbo-spring-boot-starter</artifactId>
        <version>0.2.0</version>
      </dependency>

      <!--引入zookeeper的客戶端工具-->
      <!-- https://mvnrepository.com/artifact/com.github.sgroschupf/zkclient -->
      <dependency>
        <groupId>com.github.sgroschupf</groupId>
        <artifactId>zkclient</artifactId>
        <version>0.1</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

web層pom

 <dependencies>
    <dependency>
      <groupId>com.itzmn</groupId>
      <artifactId>dubbo-service</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>com.alibaba.boot</groupId>
      <artifactId>dubbo-spring-boot-starter</artifactId>
    </dependency>

    <!--引入zookeeper的客戶端工具-->
    <!-- https://mvnrepository.com/artifact/com.github.sgroschupf/zkclient -->
    <dependency>
      <groupId>com.github.sgroschupf</groupId>
      <artifactId>zkclient</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

service層

 <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>com.alibaba.boot</groupId>
      <artifactId>dubbo-spring-boot-starter</artifactId>
    </dependency>

    <!--引入zookeeper的客戶端工具-->
    <!-- https://mvnrepository.com/artifact/com.github.sgroschupf/zkclient -->
    <dependency>
      <groupId>com.github.sgroschupf</groupId>
      <artifactId>zkclient</artifactId>
    </dependency>
  </dependencies>

2.接口設(shè)計


在service模塊新建接口,


接口實現(xiàn)類的注解,service一定是dubbo的注解

3.配置文件

# Spring boot application
spring.application.name = /springboot-dubbo
server.port = 9099
management.port = 9091

# Service version
demo.service.version = 1.0.0

# Base packages to scan Dubbo Components (e.g @Service , @Reference)
dubbo.scan.basePackages = com.itzmn.dubbo.service.impl

# Dubbo Config properties
## ApplicationConfig Bean
dubbo.application.id = springboot-dubbo
dubbo.application.name = springboot-dubbo

## ProtocolConfig Bean
dubbo.protocol.id = dubbo
dubbo.protocol.name = dubbo
dubbo.protocol.port = 20880

## RegistryConfig Bean
dubbo.registry.id = my-registry1
dubbo.registry.address = zookeeper://47.106.64.158:2181

在web層的配置文件中,配置,即可,前提,要先安裝zookeeper,才能進(jìn)行服務(wù)的注冊,然后啟動即可

4.消費者

配置

# Spring boot application
spring.application.name = dubbo-consumer-demo
server.port = 8080
management.port = 8081

# Service Version
demo.service.version = 1.0.0

# Dubbo Config properties
## ApplicationConfig Bean
dubbo.application.id = dubbo-consumer-demo
dubbo.application.name = dubbo-consumer-demo

## ProtocolConfig Bean
dubbo.protocol.id = dubbo
dubbo.protocol.name = dubbo
dubbo.protocol.port = 12345

只需將服務(wù)提供者的接口jar包引入,然后注入服務(wù)即可

注意,springboot2.0和springboot1.x與dubbo整合不一樣,

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

相關(guān)文章

  • 深入理解Spring注解@Async解決異步調(diào)用問題

    深入理解Spring注解@Async解決異步調(diào)用問題

    這篇文章主要介紹了深入理解Spring注解@Async解決異步調(diào)用問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • 深入理解Netty?FastThreadLocal優(yōu)缺點及實現(xiàn)邏輯

    深入理解Netty?FastThreadLocal優(yōu)缺點及實現(xiàn)邏輯

    本文以線上詭異問題為切入點,通過對比JDK ThreadLocal和Netty FastThreadLocal實現(xiàn)邏輯以及優(yōu)缺點,并深入解讀源碼,由淺入深理解Netty FastThreadLocal
    2023-10-10
  • SpringBoot使用prometheus監(jiān)控的示例代碼

    SpringBoot使用prometheus監(jiān)控的示例代碼

    這篇文章主要介紹了SpringBoot使用prometheus監(jiān)控的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • Java Swing中的文本框(JTextField)與文本區(qū)(JTextArea)使用實例

    Java Swing中的文本框(JTextField)與文本區(qū)(JTextArea)使用實例

    這篇文章主要介紹了Java Swing中的文本框(JTextField)與文本區(qū)(JTextArea)使用實例,Swing是一個用于開發(fā)Java應(yīng)用程序用戶界面的開發(fā)工具包,需要的朋友可以參考下
    2014-10-10
  • JAVA文件讀取常用工具類(8種)

    JAVA文件讀取常用工具類(8種)

    JAVA操作文件在經(jīng)常會使用到,本文匯總了部分JAVA操作文件的讀取常用工具類,主要介紹了8種方法,具有一定的參考價值,感興趣的可以了解一下
    2021-08-08
  • Jmeter跨線程組傳值調(diào)用實現(xiàn)圖解

    Jmeter跨線程組傳值調(diào)用實現(xiàn)圖解

    這篇文章主要介紹了Jmeter跨線程組傳值調(diào)用實現(xiàn)圖解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-07-07
  • SpringBoot?ApplicationContext接口深入分析

    SpringBoot?ApplicationContext接口深入分析

    ApplicationContext是Spring應(yīng)用程序中的中央接口,由于繼承了多個組件,使得ApplicationContext擁有了許多Spring的核心功能,如獲取bean組件,注冊監(jiān)聽事件,加載資源文件等
    2022-11-11
  • 面試必問項之Set實現(xiàn)類:TreeSet

    面試必問項之Set實現(xiàn)類:TreeSet

    這篇文章主要介紹了Java TreeSet類的簡單理解和使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2021-07-07
  • Mybatis和orcale update語句中接收參數(shù)為對象的實例代碼

    Mybatis和orcale update語句中接收參數(shù)為對象的實例代碼

    Mybatis的 mapper.xml 中 update 語句使用 if 標(biāo)簽判斷對像屬性是否為空值。本文重點給大家介紹Mybatis和orcale update語句中接收參數(shù)為對象的實例代碼,需要的朋友參考下吧
    2017-09-09
  • Caused by: java.io.IOException: DerInputStream.getLength(): lengthTag=111

    Caused by: java.io.IOException: DerInputStrea

    這篇文章主要介紹了Caused by: java.io.IOException: DerInputStream.getLength(): lengthTag=111, too big,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-10-10

最新評論