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注册中心。

  

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. [爬虫学习笔记]用于提取网页中所有链接的 Extractor 模块

            Extractor的工作是从下载的网页中将它包含的所有URL提取出来.这是个细致的工作,你需要考虑到所有可能的url的样式,比如网页中常常会包含相对路径的url,提取的时候需要将它转换 ...

  2. css中position与z-index

    position属性 在css中,position属性用来控制元素的位置信息,其取值共有4种,即static.relative.absolute.fixed. 静态定位(static) 若没有指定po ...

  3. HTML5实现屏幕手势解锁(转载)

    来源:https://github.com/lvming6816077/H5lockhttp://threejs.org/examples/http://www.inf.usi.ch/phd/wett ...

  4. IOC容器中bean的生命周期

    一.Bean的生命周期 Spring IOC容器可以管理Bean的生命周期,允许在Bean生命周期的特定点执行定制的任务. Spring IOC容器对Bean的生命周期进行管理的过程如下: (1).通 ...

  5. #define lowbit(x) ((x)&(-x))原理详解

    #define lowbit(x) ((x)&(-x)) 也可以写成如下形式: int Lowbit(x) { return x&(-x); } 例如: 1> x = 1: 十进 ...

  6. double 类型转化为Integer类型 ---DecimalFormat

    假设x是你要转换的double类型变量: 不进行四舍五入操作: (int)x 进行四舍五入操作: Integer.parseInt(new java.text.DecimalFormat(" ...

  7. linux shell 编程

    1,获取命令执行的结果,字符串拼接(脚本最常使用的功能)   cmd_result=$(date +%Y%b%d)        //使用变量获取命令执行的结果 或者 cmd_result=`date ...

  8. 【OpenCV & CUDA】OpenCV和Cuda结合编程

    一.利用OpenCV中提供的GPU模块 目前,OpenCV中已提供了许多GPU函数,直接使用OpenCV提供的GPU模块,可以完成大部分图像处理的加速操作. 基本使用方法,请参考:http://www ...

  9. OWIN概述

    关于OWIN OWIN defines a standard interface between .NET web servers and web applications. The goal of ...

  10. galera cluster DDL节点间状态不一致的问题

    近期某个系统中的galera cluseter环境发生A DDL操作后,B节点未同步的情况,同时B节点的errorlog中有如下警告信息: 2016-07-23 17:31:32 18920 [War ...