dubbo 学习笔记 -- provider端
服务端的配置文件: 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:dubbo="http://code.alibabatech.com/schema/dubbo"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://code.alibabatech.com/schema/dubbo
- http://code.alibabatech.com/schema/dubbo/dubbo.xsd ">
- <!-- Application name -->
- <dubbo:application name="Frame" />
- <!-- registry address, used for service to register itself -->
- <dubbo:registry address="multicast://224.5.6.7:1234" />
- <!-- expose this service through dubbo protocol, through port 20880 -->
- <dubbo:protocol name="dubbo" port="20880" />
- <!-- which service interface do we expose? -->
- <dubbo:service interface="merchant.shop.service.IHelloService" ref="helloService" />
- <!-- bean配置 -->
- <bean id="helloService"
- class="merchant.shop.service.impl.HelloServiceImpl">
- </bean>
- </beans>
此处interface的地址要与consumer端的一致,所以在服务端工程中新建了和客户端工程一样的路径来保存service
spring 配置文件 : providerApplicationContext.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"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
- <!-- spring 与 ibatis 衔接 -->
- <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
- <property name="configLocation" value="provider-sql-map-config.xml"></property>
- <property name="dataSource" ref="dataSource"/>
- </bean>
- <!-- 数据源基本配置 -->
- <bean id="dataSource"
- class="org.springframework.jndi.JndiObjectFactoryBean">
- <property name="jndiName">
- <value>java:/comp/env/test</value>
- </property>
- </bean>
- <!-- 事务配置 -->
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource"></property>
- </bean>
- <!-- 声明式事务管理 -->
- <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
- <property name="transactionManager" ref="transactionManager"></property>
- <property name="transactionAttributes">
- <props>
- <prop key="add*">PROPAGATION_REQUIRED</prop>
- <prop key="edit*">PROPAGATION_REQUIRED</prop>
- <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
- </props>
- </property>
- </bean>
- </beans>
服务端需要启动的两个文件如下 :
- package com.sitech.comm.dubbo;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- public class Provider {
- public static void init() throws Exception {
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"provider.xml"});
- context.start();
- singleton();
- }
- public static ApplicationContext context = null;
- public static ApplicationContext singleton() {
- if (context == null) {
- context = new ClassPathXmlApplicationContext(new String[] {"providerApplicationContext.xml"});
- }
- return context;
- };
- }
- package com.sitech.comm.dubbo;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import com.sitech.comm.log.LogWritter;
- public class ProviderInit extends HttpServlet {
- public void init() throws ServletException {
- try {
- System.out.println("初始化dubbo服务端");
- Provider.init();
- } catch (Exception e) {
- System.out.println("初始化dubbo服务端失败");
- }
- }
- }
web.xml 中增加启动如下 :
- <servlet>
- <servlet-name>ProviderInit</servlet-name>
- <servlet-class>
- com.sitech.comm.dubbo.ProviderInit
- </servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
consumer客户端就可以远程调用另一个工程的服务了
这里出问题,一般都是配置文件的问题,如数据库的连接,spring 与 ibatis 衔接
dubbo 学习笔记 -- provider端的更多相关文章
- dubbo入门学习 五 provider端的编写
1. 新建Maven Project, 里面只有接口(dubbo-service) 1.1 为什么这么做? RPC框架,不希望Consumer知道具体实现.如果实现类和接口在同一个项目中,Consum ...
- dubbo学习笔记(一)超时与重试
dubbo提供在provider和consumer端,都提供了超时(timeout)和重试(retries)的参数配置. 配置方式 provider端在<dubbo:service>中配置 ...
- dubbo学习笔记:快速搭建
搭建一个简单的dubbo服务 参考地址: dubbo官网:http://dubbo.apache.org/zh-cn/docs/user/references/registry/zookeeper.h ...
- dubbo学习笔记(二)dubbo中的filter
转:https://www.cnblogs.com/cdfive2018/p/10219730.html dubbo框架提供了filter机制的扩展点(本文基于dubbo2.6.0版本). 扩展接口 ...
- dubbo学习笔记三(全注解)
完全用注解替换掉之前的部分配置文件 项目结构 下面给出服务的的部分代码 [DubboConfiguration] @Configuration @EnableDubbo(scanBasePackage ...
- Dubbo学习笔记2:Dubbo服务提供端与消费端应用的搭建
Demo结构介绍 Demo使用Maven聚合功能,里面有三个模块,目录如下: 其中Consumer模块为服务消费者,里面TestConsumer和consumer.xml组成了基于Spring配置方式 ...
- Dubbo学习笔记4:服务消费端泛化调用与异步调用
本文借用dubbo.learn的Dubbo API方式来解释原理. 服务消费端泛化调用 前面我们讲解到,基于Spring和基于Dubbo API方式搭建简单的分布式系统时,服务消费端引入了一个SDK二 ...
- 别人的dubbo学习笔记
本文转载自:http://blog.csdn.net/tao_qq/article/details/49952229 学习dubbo,开始做一些笔记. 1> 启动dubbo-admin模块的时候 ...
- Dubbo学习笔记(二) Dubbo的基本配置
Check启动检查 根据之前的学习,我们简单理解的Dubbo远程调用的基本流程,服务提供者注册到注册中心,然后服务消费者通过监听注册中心达到远程调用的目的,那么如果注册中心中没有消费者对应的接口会怎么 ...
随机推荐
- 每日一支TED——帕特里夏·瑞安:不要固执于英语
瑞安讲述了她在科威特教学英语30年最大的 关于语言的一个感受:英语在迅速的在全世界传播,而其它的语言在逐渐的消失. 瑞安想要说的是.拥有一种国际性的语言,大家都能够理解,让全部人的 ...
- 常见Struts、Hibernate、Spring、J2EE、ibatis、Oracle等开发框架架构图及其简介
各种系统架构图及其简介 转载请保留出处,不胜人生一场醉汇总. 以下文字和架构图均在本人相关系统设计和架构方案中有所应用. 原文出处:http://space.itpub.net/6517/viewsp ...
- Jenkins 搭建
持续集成(CI continuous integration) 可以做什么? 自动构建.定时触发,或由某个事件触发.比如可以做 daily build,或每次代码提交时触发.这样可以最早发现代码编译和 ...
- source insight 配置小记
0/ Alt + T 打开 Document Options,设置字体,添加 C++ 类型文件 .cc , 删除 Plain txt 类型以避免添加 .txt 文件 1/ Alt + F12 切换函数 ...
- 分布式开源调度框架TBSchedule原理与应用
主要内容: 第一部分 TBSchedule基本概念及原理 1. 概念介绍 2. 工作原理 3. 源代码分析 4. 与其它开源调度框架对照 第二部分 TBSchedule分布式调度演示样例 1. TBS ...
- 《MySQL必知必会学习笔记》:子查询
子查询 在開始了解子查询之前,首先做下准备工作,建立3个表, 一个是customers表,当中包含:客户名字.客户ID.客户Tel等. 一个是orders表,当中包含:订单号.客户ID.订单时间等. ...
- EasyPlayer Android安卓流媒体播放器实现播放同步录像功能实现(附源码)
本文转自EasyDarwin团队John的博客:http://blog.csdn.net/jyt0551,John是EasyPusher安卓直播推流.EasyPlayer直播流媒体播放端的开发和维护者 ...
- mongoose基于mongodb的数据评论设计
var CommentSchema = { data:{type: ObjectId, ref:'Data'}, //Data数据表,此处存数据id from:{type: ObjectId, ref ...
- pyinstaller-py2exe-cx_Freeze打包第一个wxPython程序HelloWorld
pyinstaller 打包hello 7Mb ================= www.pyinstaller.org pip install pypiwin32 pip install pyin ...
- ubuntu搭建nginx
1.下载nginx压缩包 2.上传.解压 tar -zxvf nginx-1.8.0.tar.gz cd nginx-1.8.0 3.安装 make install 4.启动,停止 ,重启 服务 可 ...