创建一个父工程springdubbo,3个子工程分别为服务端provider,客户端consumer
,接口api
选择都选择maven quickstart即可

在main目录下面创建resources文件夹,并且让idea识别,选择中右击:

给父工程添加依赖,这样provider和consumer最为子项目都可以依赖,由于pom文件中的依赖子项目都需要,因此,吧依赖都添加到父工程的pom文件中。

<dependencies><dependency><groupId>com.101tec</groupId><artifactId>zkclient</artifactId><version>0.9</version></dependency><dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId><version>3.4.9</version><type>pom</type></dependency><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><version>2.5.3</version></dependency><dependency><groupId>io.netty</groupId><artifactId>netty-all</artifactId><version>4.1.6.Final</version></dependency><dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.2</version></dependency><dependency><groupId>org.javassist</groupId><artifactId>javassist</artifactId><version>3.21.0-GA</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency><!-- spring相关jar --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.3.3.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context-support</artifactId><version>4.3.3.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>4.3.3.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>4.3.3.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>4.3.3.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aspects</artifactId><version>4.3.3.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-expression</artifactId><version>4.3.3.RELEASE</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency></dependencies>

服务端provider配置如下:
创建配置文件
applicationContext-provider.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:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"><!-- 提供方应用信息,用于计算依赖关系 --><dubbo:application name="provider"/><!--使用zookeeper进行注册中心化--><dubbo:registry address="zookeeper://localhost:2181"/><!-- 用dubbo协议在20880端口暴露服务 --><dubbo:protocol name="dubbo" port="20880"/><!-- 和本地bean一样实现服务 --><bean id="serviceAPI" class="com.gblfy.dubbo.api.impl.ServiceAPIImpl"/><!-- 声明需要暴露的服务接口 --><dubbo:serviceinterface="com.gblfy.dubbo.api.ServiceAPI"ref="serviceAPI"/>
</beans>

创建一个接口实现类

public class ServiceAPIImpl implements ServiceAPI {@Overridepublic String sendMessage(String message) {return "quickstart-provider-message="+message;}
}

创建一个客户端

public class ProvierClient {/*** 1.读取配置文件* 2.创建ioc容器* 3.堵塞(状态停留,输入停止,不输入就状态一直保留)** @param args*/public static void main(String[] args) {ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-provider.xml");context.start();try {System.in.read(); // 按任意键退出} catch (IOException e) {e.printStackTrace();}}
}

依赖

<dependency><groupId>com.gblfy.dubbo</groupId><artifactId>api</artifactId><version>1.0-SNAPSHOT</version></dependency>

客户端配置:
applicationContext-consumer.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:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"><!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 --><dubbo:application name="consumer-of-helloworld-app"  /><!-- 用zookeeper进行注册中心化 --><dubbo:registry address="zookeeper://localhost:2181"/><!-- 生成远程服务代理,可以和本地bean一样使用demoService --><dubbo:referenceid="consumerService"interface="com.gblfy.dubbo.api.ServiceAPI"/></beans>

客户端

public class ConsumerClient {public static void main(String[] args) {ClassPathXmlApplicationContext context =new ClassPathXmlApplicationContext("applicationContext-consumer.xml");context.start();while (true){Scanner scanner = new Scanner(System.in);String message = scanner.next();//获取接口//从spring容器中,把实现类读出来 bean idServiceAPI serviceAPI = (ServiceAPI) context.getBean("consumerService");//message 是上面的//客户端发送消息--->>>服务端接收消息--->>>处理后,将结果返回--->>>客户端System.out.println(serviceAPI.sendMessage(message));}}
}

依赖

 <dependency><groupId>com.gblfy.dubbo</groupId><artifactId>api</artifactId><version>1.0-SNAPSHOT</version></dependency>

启动zookeeper、服务端,客户端即可测试

Spring基础环境搭建相关推荐

  1. Spring的使用——基础环境搭建以及IOC概念理解(持续更新)

    spring基础环境搭建 1.添加Spring依赖 2.编写一个Spring的配置文件 3.通过Spring的应用程序应用上下文获取对象 优点:在修改方案时可以不用修改代码,只需修改配置文件的bean ...

  2. SpringCloud Alibaba微服务实战(一) - 基础环境搭建

    说在前面 Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案.此项目包含开发分布式应用微服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来 ...

  3. 【谷粒商城基础篇】基础环境搭建

    谷粒商城笔记合集 分布式基础篇 分布式高级篇 高可用集群篇 ===简介&环境搭建=== 项目简介与分布式概念(第一.二章) 基础环境搭建(第三章) ===整合SpringCloud=== 整合 ...

  4. Spring MVC 环境搭建(一)

    一.建立 JavaWeb 项目 1.建立一个 Java 项目. 2.在项目下新建一个文件夹 webapp (命名可自取,这个目录即是网站根目录),再在该文件夹下新建一个 WEB-INF 文件夹(命名固 ...

  5. (一)Hyperledger Fabric 1.1安装部署-基础环境搭建

    在学习和开发hyperledger fabric的时候遇到了一些坑,现将自己的一些总结和心得整理如下,以期对大家有所帮助. 本次使用的宿主机环境:ubuntu,版本:Ubuntu 16.04.3 LT ...

  6. typescript+react+antd基础环境搭建

    typescript+react+antd基础环境搭建(包含样式定制) tsconfig.json 配置 // 具体配置可以看上面的链接 这里module moduleResolution的配置都会影 ...

  7. 【1】windows下IOS开发基础环境搭建

    一.目的 本文的目的是windows下IOS开发基础环境搭建做了对应的介绍,大家可根据文档步骤进行mac环境部署: 二.安装虚拟机 下载虚拟机安装文件绿色版,点击如下文件安装 获取安装包:       ...

  8. Hi3516开发笔记(三):Hi3516虚拟机基础环境搭建之交叉编译环境境搭建以及开机启动脚本分析

    若该文为原创文章,转载请注明原文出处 本文章博客地址:https://hpzwl.blog.csdn.net/article/details/121458516 长期持续项目技术分享,Shang业Di ...

  9. Hi3516开发笔记(二):Hi3516虚拟机基础环境搭建之串口调试、网络连接以及sftp文件传输

    若该文为原创文章,转载请注明原文出处 本文章博客地址:https://hpzwl.blog.csdn.net/article/details/121314575 长期持续项目技术分享,Shang业Di ...

最新文章

  1. 没事抽空学——常用界面组件属性
  2. Random类实例--猜数字游戏
  3. pandas读写csv
  4. 初识Scrapy,在充满爬虫的世界里做一个好公民
  5. 2-06 使用网络存储SAN和NAS
  6. VS Code 快捷键设置
  7. 记录-如何测试服务器是否支持ipv6
  8. [51nod1457]小K vs. 竹子
  9. 06、Flutter FFI 类
  10. 工业大数据竞赛的轴承数据集
  11. 洛谷P4207 [NOI2005]月下柠檬树(计算几何+自适应Simpson法)
  12. ESP32 测试(五): Light-sleep 模式下的电流功耗测试及特性(使用 Wi-Fi)
  13. flutter图标按钮_flutter 按钮封装 带图片的按钮,带边框的按钮,纯文字的按钮
  14. 物联网 USN架构 和 M2M架构
  15. wdm驱动的学习初步
  16. Exceptions In Java
  17. 现有关系数据库如下: 学生(学号,姓名,性别,专业) 课程(课程号,课程名,学分) 学习(学号,课程号,分数) 分别用关系代数表达式和 SQL 语句实现下列 1—5 小题(注意:每小题都要分别 写出关
  18. CBOW模型详解(基于one-hot)
  19. 杰奇linux伪静态,nginx 杰奇 nginx 伪静态规则
  20. 亚信科技安全助手卸载

热门文章

  1. 嘀嗒还是滴答_2021年顺风车车主口碑榜!滴滴、滴答、一喂顺风车成TOP3
  2. 二叉树学习之二叉查找树
  3. jsoup的Elements类
  4. sdut 区间覆盖问题
  5. C语言中文件的读取和写入
  6. 【ESSD技术解读-01】 云原生时代,阿里云 ESSD 快照服务 助力企业级数据保护
  7. mPaaS:全新移动开发平台,只为打造性能更优越的App
  8. 【MySQL】 如何在“海啸”下保命
  9. 阿里云直播转点播最佳实践
  10. 高性能开发,别点,发际线要紧!