国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

dubbo學習之服務提供者

2019-11-15 00:41:48
字體:
來源:轉載
供稿:網友
dubbo學習之服務提供者

1、簡介

  這里主要記錄如何搭建一個sPRing框架,提供一個dubbo服務,包括詳細的步驟。

2、詳細步驟

  2.1 項目目錄結構

        

  2.2 創建maven項目

    new --> Web Project ,選中Add maven support,添加maven支持,詳細如下:

    

    

    

    

    

    創建maven項目完成,可以部署到tomcat下,測試一下是否能訪問。

  2.3 添加maven依賴

    修改pom.xml,加載基礎的spring jar包 和 dubbo的jar 包,如下:    

<properties>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>    <spring-version>4.1.6.RELEASE</spring-version>  </properties>    <dependencies>      <dependency>          <groupId>org.springframework</groupId>          <artifactId>spring-core</artifactId>          <version>${spring-version}</version>      </dependency>      <dependency>          <groupId>org.springframework</groupId>          <artifactId>spring-context</artifactId>          <version>${spring-version}</version>      </dependency>      <dependency>          <groupId>org.springframework</groupId>          <artifactId>spring-web</artifactId>          <version>${spring-version}</version>      </dependency>      <dependency>      <groupId>com.alibaba</groupId>      <artifactId>dubbo</artifactId>      <version>2.6.2-SNAPSHOT</version>    </dependency>        </dependencies>

  2.4 修改applicationContext-base.xml配置文件,增加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:context="http://www.springframework.org/schema/context"    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee"    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:d="http://code.alibabatech.com/schema/dubbo"    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd       http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">        <!-- 提供方應用信息,用于計算依賴關系 -->    <d:application name="dubbo_provider"  />    <!-- 用dubbo協議在20880端口暴露服務 -->    <d:protocol name="dubbo" port="20880" />    <!-- 使用zookeeper集群注冊中心暴露服務地址 -->   <!-- 這里是用的偽集群方式,可參考“zookeeper初始*********”博客部分  -->    <d:registry address="zookeeper://192.168.1.102:2181?backup=192.168.1.102:2182,192.168.1.102:2183" default="true" />        <!-- 聲明需要暴露的服務接口 -->    <d:service interface="com.wei.interfaces.DemoService" ref="demoService" />    <!-- 和本地服務一樣實現服務 -->        <bean id="demoService" class="com.wei.services.DemoServiceImpl" />    </beans>

  2.5 修改web.xml,如下:    

  <listener>      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  </listener>  <context-param>    <param-name>contextConfigLocation</param-name>    <param-value>classpath:*.xml</param-value>  </context-param>

  2.6 編寫對外發布的dubbo接口,如下:  

package com.wei.interfaces;/** * 單獨打包 * @author wed * */public interface DemoService {    public String sayHello(String name);}

  2.7 編寫對外發布dubbo接口的實現類,如下:

package com.wei.services;import com.wei.interfaces.DemoService;public class DemoServiceImpl implements DemoService {    @Override    public String sayHello(String name) {        return "hello "+ name;    }}

  2.8 啟動服務,查看dubbo管理控制臺,如下:

    可以看到,在提供者tab頁面已經有ip信息,點擊進去可以看到對應的服務信息。

2.8 注意點:

    (1)把interfaces單獨達成jar包,后面消費者要用到。

    (2)這一步用到的zookeeper地址,是前面配好的zookeeper偽集群方式;如果沒有配置多個節點,也可以配置為單節點方式,或者是multicast注冊中心。

  


上一篇:JAVA &amp;&amp; JSON

下一篇:登錄攔截功能

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临猗县| 资中县| 郑州市| 新邵县| 都兰县| 抚松县| 哈密市| 卢氏县| 昆山市| 鄂伦春自治旗| 陆良县| 延吉市| 右玉县| 西安市| 兴义市| 潞城市| 陆河县| 若羌县| 西城区| 新郑市| 高邑县| 南川市| 大宁县| 孝感市| 阳春市| 莲花县| 兴业县| 澄江县| 蛟河市| 郑州市| 仁怀市| 唐山市| 金乡县| 盱眙县| 确山县| 广饶县| 油尖旺区| 集贤县| 吴堡县| 尼木县| 上虞市|