- 浏览: 213646 次
- 性别:
- 来自: 杭州
-
文章分类
最新评论
-
hus20120405:
很不错,我运行起来了
log4jdbc日志框架介绍 -
Roshomon:
牛叉 找了很多解决方案 你的OK了
plsql ora-12154 TNS 无法处理服务名 -
ackley:
赞!谢谢!
Cannot access NLS data files or invalid ...
采用dubbo客户端访问dubbo发布的rest服务,接上一篇。
1)启动类
package cn.gov.zjport.dubborest.test;
public class DemoConsumer {
public static void main(String[] args) {
com.alibaba.dubbo.container.Main.main(args);
}
}
2)beans-consumer.xml
3.spring 配置文件:spring-business-service.xml
4.dubbo配置文件:spring-dubbo-service.xml
5. 客户端访问类:DemoStart
6. 运行 DemoConsumer
在run configuration 里设置 vm参数
-Ddubbo.spring.config=classpath:test/beans-consumer.xml
然后运行,就能打印出访问结果。
1)启动类
package cn.gov.zjport.dubborest.test;
public class DemoConsumer {
public static void main(String[] args) {
com.alibaba.dubbo.container.Main.main(args);
}
}
2)beans-consumer.xml
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd"> <!--service服务 --> <import resource="classpath:/test/spring/consumer/spring-business-service.xml" /> <import resource="classpath:/test/spring/consumer/spring-dubbo-service.xml" /> </beans>
3.spring 配置文件:spring-business-service.xml
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd"> <bean class="cn.gov.zjport.dubborest.test.DemoStart" init-method="start"> <property name="restDemoService" ref="restDemoService" /> </bean> </beans>
4.dubbo配置文件:spring-dubbo-service.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- - Copyright 1999-2011 Alibaba Group. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <dubbo:application name="dubborest-test-consumer" owner="dubborest" organization="zjport"/> <dubbo:registry address="zookeeper://192.168.3.110:2181"/> <!--uncomment this if you want to test dubbo's monitor--> <!--<dubbo:monitor protocol="registry"/>--> <dubbo:reference id="restDemoService" interface="cn.gov.zjport.dubborest.service.rest.RestDemoService"/> </beans>
5. 客户端访问类:DemoStart
package cn.gov.zjport.dubborest.test; import cn.gov.zjport.dubborest.pojo.User; import cn.gov.zjport.dubborest.service.rest.RestDemoService; public class DemoStart { private RestDemoService restDemoService; public void start(){ System.out.println(restDemoService.search("zhenggm")); User user=new User(); user.setId(1L); user.setName("zhengxl"); System.out.println(restDemoService.post(user)); System.out.println(restDemoService.get("zhangsan")); } public RestDemoService getRestDemoService() { return restDemoService; } public void setRestDemoService(RestDemoService restDemoService) { this.restDemoService = restDemoService; } }
6. 运行 DemoConsumer
在run configuration 里设置 vm参数
-Ddubbo.spring.config=classpath:test/beans-consumer.xml
然后运行,就能打印出访问结果。
发表评论
文章已被作者锁定,不允许评论。
-
zookeeper docker 集群安装
2022-10-14 17:18 1441. 下载镜像 docker pull docker.io/z ... -
Kafka学习笔记【三】-JAVA调用示例
2018-05-29 08:35 5691. pom.xml <dependency> ... -
Kafka学习笔记【二】-安装
2018-05-24 08:20 354kafka的安装如下: 一、准备环境 1) 三台服务器 ... -
Kafka学习笔记【一】-原理
2018-05-18 09:23 249一、kafka的重要概念 1. kafka 分为 Produ ... -
rabbitMQ学习笔记【三】-haproxy部署 原创
2018-04-11 16:11 374一、下载 https://fossies.org/lin ... -
rabbitMQ学习笔记【二】-集群部署 原创
2018-04-03 19:40 397一、准备工作 三台机器hosts: 192.168.3 ... -
rabbitMQ学习笔记【一】-单机部署 原创
2018-03-19 16:04 405公司对外接入需要支持MQ,最终选定rabbitMQ.本文 ... -
HttpClient 学习笔记【原创】
2017-09-07 19:28 1897HttpClient 某些方法的作用梳理。本文的测试基于htt ... -
关于dubbo的思考【原创】
2016-09-21 08:23 1327最近在看dubbo的文档,有些内容结合自己的思考记录一下 1. ... -
dubbo http webservice 服务学习笔记【原创】
2016-09-11 19:12 6479学习了 dubbo rest服务之后,再使用dubbo htt ... -
dubbo rest 服务学习笔记(三)【原创】
2016-09-09 19:34 8763在配置过程中遇到两个 ... -
dubbo rest 服务学习笔记(一)【原创】
2016-09-09 19:07 6114dubbo是很好的服务治理工具,包含了注册,路由,监控 ... -
RocketMq数据处理
2016-06-27 08:58 620这篇讲实践中数据丢失、顺序幂等处理、性能压测,有时间再写 -
RocketMq学习笔记(2)【原创】
2016-06-27 08:55 1134前一篇文章http://zhenggm.i ... -
MS MQ 使用实践【原创】
2016-06-26 14:58 7801. 参照百度经验http://jingyan.baidu.c ... -
RocketMq学习笔记【原创】
2016-06-23 14:05 1587前段时间在实施分布式数据库的过程中,使用过rocketMQ, ... -
rest的调用 java 示例代码【原创】
2016-06-20 15:35 11701. 服务端示例代码(如何搭建rest服务,请看上一篇) ... -
jersey2 与 spring4 整合实践【原创】
2016-06-13 15:35 4982前几年用过jeysey,那都是1.x版本的,jersey2有很 ... -
java nio入门
2010-03-04 17:22 952首先了解下所谓的java nio是个什么东西! ... -
spring http invoker学习笔记
2010-01-04 16:58 3710概念 Spring HTTP invoker是spring框架 ...
相关推荐
【Dubbo学习笔记】 Dubbo是一款高性能、轻量级的Java RPC框架,它旨在提供面向接口的远程方法调用、智能容错与负载均衡、服务自动注册与发现等核心功能,帮助开发者构建分布式服务架构。以下是对Dubbo基础知识、...
- **协议(Protocol)**: 服务交互的通信协议,如Dubbo默认的dubbo协议,HTTP,REST等。 - **监控中心(Monitor)**: 统计服务的调用次数、调用时间、失败比例等,用于故障排查和性能优化。 2. **Zookeeper在...
《Dubbo学习笔记详解》 Dubbo,作为阿里巴巴开源的一款高性能、轻量级的服务治理框架,已经在Java开发者中广受欢迎。它主要应用于分布式系统中的服务调用,提供服务注册、服务发现、负载均衡、容错处理等核心功能,...
【SpringCloud笔记】是关于微服务架构的学习资料,主要涵盖了SpringCloud的基本概念、核心组件以及实战技巧。在学习SpringCloud之前,需要具备一定的基础知识,包括IDEA、JDK8、Maven、SpringBoot以及Linux环境的...
# SpringCloud课堂笔记知识点解析 ## 一、微服务概述 ### 1.1 微服务定义 微服务架构作为一种新兴的设计模式,旨在通过将单个应用程序分解为多个小型、独立的服务来提升软件的可扩展性和灵活性。这些服务通常遵循...
5. **Dubbo**:阿里巴巴开源的服务框架,支持高性能的 RPC 服务输出和输入,与 Spring 框架无缝集成。 #### 八、微服务架构 1. **定义**:微服务架构是一种将应用分解为一系列小服务的设计模式,每个服务独立运行...
12. **微服务架构**:理解微服务的概念,如何通过Spring Cloud或Dubbo实现服务拆分,提高系统的可扩展性和可维护性。 13. **DRP业务流程**:深入理解DRP业务流程,包括采购、销售、库存管理等,将业务逻辑有效地...