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

Dubbo在Spring和Spring Boot中的使用詳解

 更新時(shí)間:2017年10月31日 14:32:15   作者:自在流云  
這篇文章主要介紹了Dubbo在Spring和Spring Boot中的使用詳解,需要的朋友可以參考下

一、在Spring中使用Dubbo

1、Maven依賴

<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>dubbo</artifactId>
  <version>2.5.3.6</version>
  <exclusions>
    <exclusion>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
    </exclusion>
    <exclusion>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.springframework</groupId>
      <artifactId>spring</artifactId>
    </exclusion>
    <exclusion>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>com.github.sgroschupf</groupId>
  <artifactId>zkclient</artifactId>
  <version>0.1</version>
</dependency>

2、DUBBO生產(chǎn)者注冊(cè)到zookeeper的xml配置方式

<?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
    ">
 <!-- 具體的實(shí)現(xiàn)bean -->
 <bean id="demoService"
 class="com.unj.dubbotest.provider.impl.DemoServiceImpl" />
 <!-- 提供方應(yīng)用信息,用于計(jì)算依賴關(guān)系 -->
 <dubbo:application name="xixi_provider" />
 <!-- 使用multicast廣播注冊(cè)中心暴露服務(wù)地址 
 <dubbo:registry address="multicast://224.5.6.7:1234" />-->
 <!-- 使用zookeeper注冊(cè)中心暴露服務(wù)地址 -->
 <dubbo:registry address="zookeeper://127.0.0.1:2181" />
 <!-- 用dubbo協(xié)議在20880端口暴露服務(wù) -->
 <dubbo:protocol name="dubbo" port="20880" />
 <!-- 聲明需要暴露的服務(wù)接口 -->
 <dubbo:service interface="com.unj.dubbotest.provider.DemoService" version="mys"
 ref="demoService" />
</beans>

3、DUBBO消費(fèi)者注冊(cè)到zookeeper的xml配置方式

<?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 
    ">
 <!-- 消費(fèi)者應(yīng)用信息,用于提供依賴關(guān)系 -->
 <dubbo:application name="consumer-of-helloworld-app" />
 <!-- 注冊(cè)地址,用于消費(fèi)者尋找服務(wù) -->
 <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181,10.128.3.33:2181" />
 <dubbo:consumer timeout="5000" />
 <!-- 引用的服務(wù) -->
 <dubbo:reference id="demoService"interface="com.unj.dubbotest.provider.DemoService" version="mys" />
</beans>

二、在Spring Boot中使用Dubbo

在Spring Boot中使用Dubbo,不需要使用xml的方式來配置生產(chǎn)者和消費(fèi)者,需要使用@Bean注解的方式來進(jìn)行配置。

1、Maven依賴

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <version>1.2.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter</artifactId>
  <version>1.2.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>dubbo</artifactId>
  <version>2.5.3.6</version>
  <exclusions>
    <exclusion>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
    </exclusion>
    <exclusion>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.springframework</groupId>
      <artifactId>spring</artifactId>
    </exclusion>
    <exclusion>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>com.github.sgroschupf</groupId>
  <artifactId>zkclient</artifactId>
  <version>0.1</version>
</dependency>

2、Dubbo基礎(chǔ)配置

public class DubboBaseConfig {
  @Bean
  public RegistryConfig registry() {
    RegistryConfig registryConfig = new RegistryConfig();
    registryConfig.setAddress("127.0.0.1:2181");
    registryConfig.setProtocol("zookeeper");
    return registryConfig;
  }
  @Bean
  public ApplicationConfig application() {
    ApplicationConfig applicationConfig = new ApplicationConfig();
    applicationConfig.setName("testApp");
    return applicationConfig;
  }
  @Bean
  public MonitorConfig monitorConfig() {
    MonitorConfig mc = new MonitorConfig();
    mc.setProtocol("registry");
    return mc;
  }
  @Bean
  public ReferenceConfig referenceConfig() {
    ReferenceConfig rc = new ReferenceConfig();
    rc.setMonitor(monitorConfig());
    return rc;
  }
  @Bean
  public ProtocolConfig protocol() {
    ProtocolConfig protocolConfig = new ProtocolConfig();
    protocolConfig.setPort(20880);
    return protocolConfig;
  }
  @Bean
  public ProviderConfig provider() {
    ProviderConfig providerConfig = new ProviderConfig();
    providerConfig.setMonitor(monitorConfig());
    return providerConfig;
  }
}

3、Dubbo生產(chǎn)者配置,需要繼承Dubbo基礎(chǔ)配置

@Configuration
public class ExportServiceConfig extends DubboBaseConfig {
  @Bean
  public ServiceBean<Person> personServiceExport(Person person) {
    ServiceBean<Person> serviceBean = new ServiceBean<Person>();
    serviceBean.setProxy("javassist");
    serviceBean.setVersion("myversion");
    serviceBean.setInterface(Person.class.getName());
    serviceBean.setRef(person);
    serviceBean.setTimeout(5000);
    serviceBean.setRetries(3);
    return serviceBean;
  }
}

4、Dubbo消費(fèi)者配置,需要繼承Dubbo基礎(chǔ)配置

@Configuration
public class ReferenceConfig extends DubboBaseConfig {
  @Bean
  public ReferenceBean<Person> person() {
    ReferenceBean<Person> ref = new ReferenceBean<>();
    ref.setVersion("myversion");
    ref.setInterface(Person.class);
    ref.setTimeout(5000);
    ref.setRetries(3);
    ref.setCheck(false);
    return ref;
  }
}

5、直接從Spring容器中拿去Person接口即可。

總結(jié)

以上所述是小編給大家介紹的Dubbo在Spring和Spring Boot中的使用詳解,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • java實(shí)現(xiàn)dijkstra最短路徑尋路算法

    java實(shí)現(xiàn)dijkstra最短路徑尋路算法

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)dijkstra最短路徑尋路算法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • IDEA無法識(shí)別相關(guān)module模塊問題的解決過程

    IDEA無法識(shí)別相關(guān)module模塊問題的解決過程

    這篇文章主要給大家介紹了關(guān)于IDEA無法識(shí)別相關(guān)module模塊問題的解決過程,文中通過圖文介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用IDEA具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-07-07
  • SWT(JFace)體驗(yàn)之FillLayout布局

    SWT(JFace)體驗(yàn)之FillLayout布局

    FillLayout是非常簡(jiǎn)單的一種布局方式,它會(huì)以同樣大小對(duì)父組件中的子組件進(jìn)行布局,這些子組件將以一行或一列的形式排列。
    2009-06-06
  • springboot如何使用thymeleaf模板訪問html頁面

    springboot如何使用thymeleaf模板訪問html頁面

    springboot中推薦使用thymeleaf模板,使用html作為頁面展示。那么如何通過Controller來訪問來訪問html頁面呢?下面通過本文給大家詳細(xì)介紹,感興趣的朋友跟隨腳本之家小編一起看看吧
    2018-05-05
  • java中類之間的數(shù)據(jù)傳遞方式

    java中類之間的數(shù)據(jù)傳遞方式

    這篇文章主要介紹了java中類之間的數(shù)據(jù)傳遞方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • 解決@RequestBody接收json對(duì)象報(bào)錯(cuò)415的問題

    解決@RequestBody接收json對(duì)象報(bào)錯(cuò)415的問題

    這篇文章主要介紹了解決@RequestBody接收json對(duì)象報(bào)錯(cuò)415的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • 徹底解決IDEA中SpringBoot熱部署無效的問題(推薦)

    徹底解決IDEA中SpringBoot熱部署無效的問題(推薦)

    這篇文章主要介紹了徹底解決IDEA中SpringBoot熱部署無效的問題,本文給大家?guī)韱栴}原因分析通過圖文實(shí)例相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2020-09-09
  • Mybatis-Plus實(shí)現(xiàn)多主鍵批量保存及更新詳情

    Mybatis-Plus實(shí)現(xiàn)多主鍵批量保存及更新詳情

    這篇文章主要介紹了Mybatis-Plus實(shí)現(xiàn)多主鍵批量保存及更新詳情,文章通過圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-09-09
  • 迪米特法則_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理

    迪米特法則_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理

    這篇文章主要介紹了迪米特法則,迪米特法則就是一個(gè)在類創(chuàng)建方法和屬性時(shí)需要遵守的法則,有興趣的可以了解一下
    2017-08-08
  • JavaBean字段如何防止非空賦值

    JavaBean字段如何防止非空賦值

    這篇文章主要介紹了JavaBean字段如何防止非空賦值的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08

最新評(píng)論