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 包,如下:    

  1. <properties>
  2. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  3. <spring-version>4.1.6.RELEASE</spring-version>
  4. </properties>
  5.  
  6. <dependencies>
  7. <dependency>
  8. <groupId>org.springframework</groupId>
  9. <artifactId>spring-core</artifactId>
  10. <version>${spring-version}</version>
  11. </dependency>
  12. <dependency>
  13. <groupId>org.springframework</groupId>
  14. <artifactId>spring-context</artifactId>
  15. <version>${spring-version}</version>
  16. </dependency>
  17. <dependency>
  18. <groupId>org.springframework</groupId>
  19. <artifactId>spring-web</artifactId>
  20. <version>${spring-version}</version>
  21. </dependency>
  22. <dependency>
  23. <groupId>com.alibaba</groupId>
  24. <artifactId>dubbo</artifactId>
  25. <version>2.6.2-SNAPSHOT</version>
  26. </dependency>
  27.  
  28. </dependencies>

  2.4 修改applicationContext-base.xml配置文件,增加dubbo的配置,如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  4. xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee"
  5. xmlns:aop="http://www.springframework.org/schema/aop" xmlns:d="http://code.alibabatech.com/schema/dubbo"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
  8. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
  9. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
  10. http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
  11. http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
  12.  
  13. <!-- 提供方应用信息,用于计算依赖关系 -->
  14. <d:application name="dubbo_provider" />
  15. <!-- 用dubbo协议在20880端口暴露服务 -->
  16. <d:protocol name="dubbo" port="20880" />
  17. <!-- 使用zookeeper集群注册中心暴露服务地址 -->
       <!-- 这里是用的伪集群方式,可参考“zookeeper初始*********”博客部分 -->
    <d:registry address="zookeeper://192.168.1.102:2181?backup=192.168.1.102:2182,192.168.1.102:2183" default="true" />
  18.  
  19. <!-- 声明需要暴露的服务接口 -->
  20. <d:service interface="com.wei.interfaces.DemoService" ref="demoService" />
  21. <!-- 和本地服务一样实现服务 -->
  22. <bean id="demoService" class="com.wei.services.DemoServiceImpl" />
  23.  
  24. </beans>

  2.5 修改web.xml,如下:    

  1. <listener>
  2. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  3. </listener>
  4. <context-param>
  5. <param-name>contextConfigLocation</param-name>
  6. <param-value>classpath:*.xml</param-value>
  7. </context-param>

  2.6 编写对外发布的dubbo接口,如下:  

  1. package com.wei.interfaces;
  2.  
  3. /**
  4. * 单独打包
  5. * @author wed
  6. *
  7. */
  8. public interface DemoService {
  9.  
  10. public String sayHello(String name);
  11. }

  2.7 编写对外发布dubbo接口的实现类,如下:

  1. package com.wei.services;
  2.  
  3. import com.wei.interfaces.DemoService;
  4.  
  5. public class DemoServiceImpl implements DemoService {
  6.  
  7. @Override
  8. public String sayHello(String name) {
  9. return "hello "+ name;
  10. }
  11. }

  2.8 启动服务,查看dubbo管理控制台,如下:

    可以看到,在提供者tab页面已经有ip信息,点击进去可以看到对应的服务信息。

2.8 注意点:

    (1)把interfaces单独达成jar包,后面消费者要用到。

    (2)这一步用到的zookeeper地址,是前面配好的zookeeper伪集群方式;如果没有配置多个节点,也可以配置为单节点方式,或者是multicast注册中心。

  

dubbo学习之服务提供者的更多相关文章

  1. Dubbo学习小记

    前言 周一入职的新公司,到了公司第一件事自然是要熟悉新公司使用的各种技术,搭建本地的环境. 熟悉新公司技术的过程中,首先就是Maven,这个前面已经写过文章了,然后就是Dubbo----公司的服务都是 ...

  2. dubbo学习(zz)

    dubbo学习 博客分类: 开源软件   Dubbo是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被广泛应用于阿里巴巴集团的各成员站 ...

  3. Dubbo学习(六) dubbo 架构图 以及调用过程

    一.Dubbo结构图   duubo结构图 我们解释以下这个架构图:Consumer服务消费者,Provider服务提供者.Container服务容器.消费当然是invoke提供者了,invoke这条 ...

  4. Dubbo学习(一) Dubbo原理浅析

    一.初入Dubbo Dubbo学习文档: http://dubbo.incubator.apache.org/books/dubbo-user-book/ http://dubbo.incubator ...

  5. dubbo学习小结

    dubbo学习小结 参考: https://blog.csdn.net/paul_wei2008/article/details/19355681 https://blog.csdn.net/liwe ...

  6. Dubbo学习系列之十三(Mycat数据库代理)

    软件界有只猫,不用我说,各位看官肯定知道是哪只,那就是大名鼎鼎的Tomcat,现在又来了一只猫,据说是位东方萌妹子,暂且认作Tom猫的表妹,本来叫OpencloudDB,后又改名为Mycat,或许Ca ...

  7. Dubbo学习系列之八(分布式事务之MQ方案)

    自从小王玩起了微服务,发现微服务果然很强大,好处真是太多,心中暗喜,然而,却也遇到了分布式中最棘手的问题:分布式事务.小王遍访各路神仙,也无个完美开源解决方案,当然,也有些实际可行的手法,虽不算完美, ...

  8. Dubbo学习系列之九(Shiro+JWT权限管理)

    村长让小王给村里各系统来一套SSO方案做整合,隔壁的陈家村流行使用Session+认证中心方法,但小王想尝试点新鲜的,于是想到了JWT方案,那JWT是啥呢?JavaWebToken简称JWT,就是一个 ...

  9. Dubbo学习系列之十五(Seata分布式事务方案TCC模式)

    上篇的续集. 工具: Idea201902/JDK11/Gradle5.6.2/Mysql8.0.11/Lombok0.27/Postman7.5.0/SpringBoot2.1.9/Nacos1.1 ...

随机推荐

  1. 字符串 - 近似回文词 --- csu 1328

    近似回文词 Problem's Link:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 analyse: 直接暴力枚举每一个终点,然后枚举 ...

  2. 重构第8天:使用委托代替继承(Replace Inheritance with Delegation)

    理解:根本没有父子关系的类中使用继承是不合理的,可以用委派的方式来代替. 详解:我们经常在错误的场景使用继承.继承应该在仅仅有逻辑关系的环境中使用,而很多情况下却被使用在达到方便为目的的环境中. 看下 ...

  3. 【循序渐进学Python】2. Python中的序列——列表和元组

    序列概览 在Python中有六种内建的序列:列表.元组.字符串.Unicode字符串.buffer对象和xrange对象.在这里暂时只讨论列表和元组.列表和元组的主要区别在于:列表可以修改,元组(不可 ...

  4. 论那些年我们讨论过的Bank系统!

    今天呢我就和大家分享一下怎样用对象数组的形式来实现一个简单的银行系统, 首先呢,跟大家介绍一下这个简单的银行操作系统要实现的一些主要的功能: 主要功能有 : 1.开户功能 2.存款 3.取款 4.转账 ...

  5. 重新想象 Windows 8 Store Apps (36) - 通知: Tile 详解

    [源码下载] 重新想象 Windows 8 Store Apps (36) - 通知: Tile 详解 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 通知 Tile ...

  6. 重新想象 Windows 8 Store Apps (41) - 打印

    [源码下载] 重新想象 Windows 8 Store Apps (41) - 打印 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 打印 示例1.需要打印的文档Pr ...

  7. 重新想象 Windows 8.1 Store Apps (93) - 控件增强: GridView, ListView

    [源码下载] 重新想象 Windows 8.1 Store Apps (93) - 控件增强: GridView, ListView 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...

  8. C#根据CPU+磁盘标号来注册软件

    很多私人软件都需要自己的作品出售给别人只能一台电脑使用,不可以随便一个电脑都可以运行自己的软件,所以就有了软件注册限制的控制,收集了一个注册软件的帮助类,分享记录一下. 功能介绍:    根据CPU+ ...

  9. [moka同学笔记]一、Yii2.0课程笔记(魏曦老师教程)

    第一节   第二节             课程内容     

  10. Webhooks PHP

    Webhooks/Parse When webhooks are triggered in the gateway, a notification is sent as a POST request ...