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注册中心。
dubbo学习之服务提供者的更多相关文章
- Dubbo学习小记
前言 周一入职的新公司,到了公司第一件事自然是要熟悉新公司使用的各种技术,搭建本地的环境. 熟悉新公司技术的过程中,首先就是Maven,这个前面已经写过文章了,然后就是Dubbo----公司的服务都是 ...
- dubbo学习(zz)
dubbo学习 博客分类: 开源软件 Dubbo是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被广泛应用于阿里巴巴集团的各成员站 ...
- Dubbo学习(六) dubbo 架构图 以及调用过程
一.Dubbo结构图 duubo结构图 我们解释以下这个架构图:Consumer服务消费者,Provider服务提供者.Container服务容器.消费当然是invoke提供者了,invoke这条 ...
- Dubbo学习(一) Dubbo原理浅析
一.初入Dubbo Dubbo学习文档: http://dubbo.incubator.apache.org/books/dubbo-user-book/ http://dubbo.incubator ...
- dubbo学习小结
dubbo学习小结 参考: https://blog.csdn.net/paul_wei2008/article/details/19355681 https://blog.csdn.net/liwe ...
- Dubbo学习系列之十三(Mycat数据库代理)
软件界有只猫,不用我说,各位看官肯定知道是哪只,那就是大名鼎鼎的Tomcat,现在又来了一只猫,据说是位东方萌妹子,暂且认作Tom猫的表妹,本来叫OpencloudDB,后又改名为Mycat,或许Ca ...
- Dubbo学习系列之八(分布式事务之MQ方案)
自从小王玩起了微服务,发现微服务果然很强大,好处真是太多,心中暗喜,然而,却也遇到了分布式中最棘手的问题:分布式事务.小王遍访各路神仙,也无个完美开源解决方案,当然,也有些实际可行的手法,虽不算完美, ...
- Dubbo学习系列之九(Shiro+JWT权限管理)
村长让小王给村里各系统来一套SSO方案做整合,隔壁的陈家村流行使用Session+认证中心方法,但小王想尝试点新鲜的,于是想到了JWT方案,那JWT是啥呢?JavaWebToken简称JWT,就是一个 ...
- Dubbo学习系列之十五(Seata分布式事务方案TCC模式)
上篇的续集. 工具: Idea201902/JDK11/Gradle5.6.2/Mysql8.0.11/Lombok0.27/Postman7.5.0/SpringBoot2.1.9/Nacos1.1 ...
随机推荐
- 字符串 - 近似回文词 --- csu 1328
近似回文词 Problem's Link:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 analyse: 直接暴力枚举每一个终点,然后枚举 ...
- 重构第8天:使用委托代替继承(Replace Inheritance with Delegation)
理解:根本没有父子关系的类中使用继承是不合理的,可以用委派的方式来代替. 详解:我们经常在错误的场景使用继承.继承应该在仅仅有逻辑关系的环境中使用,而很多情况下却被使用在达到方便为目的的环境中. 看下 ...
- 【循序渐进学Python】2. Python中的序列——列表和元组
序列概览 在Python中有六种内建的序列:列表.元组.字符串.Unicode字符串.buffer对象和xrange对象.在这里暂时只讨论列表和元组.列表和元组的主要区别在于:列表可以修改,元组(不可 ...
- 论那些年我们讨论过的Bank系统!
今天呢我就和大家分享一下怎样用对象数组的形式来实现一个简单的银行系统, 首先呢,跟大家介绍一下这个简单的银行操作系统要实现的一些主要的功能: 主要功能有 : 1.开户功能 2.存款 3.取款 4.转账 ...
- 重新想象 Windows 8 Store Apps (36) - 通知: Tile 详解
[源码下载] 重新想象 Windows 8 Store Apps (36) - 通知: Tile 详解 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 通知 Tile ...
- 重新想象 Windows 8 Store Apps (41) - 打印
[源码下载] 重新想象 Windows 8 Store Apps (41) - 打印 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 打印 示例1.需要打印的文档Pr ...
- 重新想象 Windows 8.1 Store Apps (93) - 控件增强: GridView, ListView
[源码下载] 重新想象 Windows 8.1 Store Apps (93) - 控件增强: GridView, ListView 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...
- C#根据CPU+磁盘标号来注册软件
很多私人软件都需要自己的作品出售给别人只能一台电脑使用,不可以随便一个电脑都可以运行自己的软件,所以就有了软件注册限制的控制,收集了一个注册软件的帮助类,分享记录一下. 功能介绍: 根据CPU+ ...
- [moka同学笔记]一、Yii2.0课程笔记(魏曦老师教程)
第一节 第二节 课程内容
- Webhooks PHP
Webhooks/Parse When webhooks are triggered in the gateway, a notification is sent as a POST request ...