服务端的配置文件:    provider.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://code.alibabatech.com/schema/dubbo
  8. http://code.alibabatech.com/schema/dubbo/dubbo.xsd         ">
  9. <!-- Application name -->
  10. <dubbo:application name="Frame"  />
  11. <!-- registry address, used for service to register itself -->
  12. <dubbo:registry address="multicast://224.5.6.7:1234" />
  13. <!-- expose this service through dubbo protocol, through port 20880 -->
  14. <dubbo:protocol name="dubbo" port="20880" />
  15. <!-- which service interface do we expose? -->
  16. <dubbo:service interface="merchant.shop.service.IHelloService" ref="helloService" />
  17. <!-- bean配置 -->
  18. <bean id="helloService"
  19. class="merchant.shop.service.impl.HelloServiceImpl">
  20. </bean>
  21. </beans>

此处interface的地址要与consumer端的一致,所以在服务端工程中新建了和客户端工程一样的路径来保存service

spring 配置文件 : providerApplicationContext.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
  5. <!-- spring 与 ibatis 衔接 -->
  6. <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  7. <property name="configLocation" value="provider-sql-map-config.xml"></property>
  8. <property name="dataSource" ref="dataSource"/>
  9. </bean>
  10. <!-- 数据源基本配置 -->
  11. <bean id="dataSource"
  12. class="org.springframework.jndi.JndiObjectFactoryBean">
  13. <property name="jndiName">
  14. <value>java:/comp/env/test</value>
  15. </property>
  16. </bean>
  17. <!-- 事务配置 -->
  18. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  19. <property name="dataSource" ref="dataSource"></property>
  20. </bean>
  21. <!-- 声明式事务管理 -->
  22. <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
  23. <property name="transactionManager" ref="transactionManager"></property>
  24. <property name="transactionAttributes">
  25. <props>
  26. <prop key="add*">PROPAGATION_REQUIRED</prop>
  27. <prop key="edit*">PROPAGATION_REQUIRED</prop>
  28. <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
  29. </props>
  30. </property>
  31. </bean>
  32. </beans>

服务端需要启动的两个文件如下 :

  1. package com.sitech.comm.dubbo;
  2. import org.springframework.context.ApplicationContext;
  3. import org.springframework.context.support.ClassPathXmlApplicationContext;
  4. public class Provider {
  5. public static void init() throws Exception {
  6. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"provider.xml"});
  7. context.start();
  8. singleton();
  9. }
  10. public static ApplicationContext context = null;
  11. public static ApplicationContext singleton() {
  12. if (context == null) {
  13. context = new ClassPathXmlApplicationContext(new String[] {"providerApplicationContext.xml"});
  14. }
  15. return context;
  16. };
  17. }
  1. package com.sitech.comm.dubbo;
  2. import javax.servlet.ServletException;
  3. import javax.servlet.http.HttpServlet;
  4. import com.sitech.comm.log.LogWritter;
  5. public class ProviderInit extends HttpServlet {
  6. public void init() throws ServletException {
  7. try {
  8. System.out.println("初始化dubbo服务端");
  9. Provider.init();
  10. } catch (Exception e) {
  11. System.out.println("初始化dubbo服务端失败");
  12. }
  13. }
  14. }

web.xml 中增加启动如下 :

  1. <servlet>
  2. <servlet-name>ProviderInit</servlet-name>
  3. <servlet-class>
  4. com.sitech.comm.dubbo.ProviderInit
  5. </servlet-class>
  6. <load-on-startup>1</load-on-startup>
  7. </servlet>

consumer客户端就可以远程调用另一个工程的服务了

这里出问题,一般都是配置文件的问题,如数据库的连接,spring 与 ibatis 衔接

dubbo 学习笔记 -- provider端的更多相关文章

  1. dubbo入门学习 五 provider端的编写

    1. 新建Maven Project, 里面只有接口(dubbo-service) 1.1 为什么这么做? RPC框架,不希望Consumer知道具体实现.如果实现类和接口在同一个项目中,Consum ...

  2. dubbo学习笔记(一)超时与重试

    dubbo提供在provider和consumer端,都提供了超时(timeout)和重试(retries)的参数配置. 配置方式 provider端在<dubbo:service>中配置 ...

  3. dubbo学习笔记:快速搭建

    搭建一个简单的dubbo服务 参考地址: dubbo官网:http://dubbo.apache.org/zh-cn/docs/user/references/registry/zookeeper.h ...

  4. dubbo学习笔记(二)dubbo中的filter

    转:https://www.cnblogs.com/cdfive2018/p/10219730.html dubbo框架提供了filter机制的扩展点(本文基于dubbo2.6.0版本). 扩展接口 ...

  5. dubbo学习笔记三(全注解)

    完全用注解替换掉之前的部分配置文件 项目结构 下面给出服务的的部分代码 [DubboConfiguration] @Configuration @EnableDubbo(scanBasePackage ...

  6. Dubbo学习笔记2:Dubbo服务提供端与消费端应用的搭建

    Demo结构介绍 Demo使用Maven聚合功能,里面有三个模块,目录如下: 其中Consumer模块为服务消费者,里面TestConsumer和consumer.xml组成了基于Spring配置方式 ...

  7. Dubbo学习笔记4:服务消费端泛化调用与异步调用

    本文借用dubbo.learn的Dubbo API方式来解释原理. 服务消费端泛化调用 前面我们讲解到,基于Spring和基于Dubbo API方式搭建简单的分布式系统时,服务消费端引入了一个SDK二 ...

  8. 别人的dubbo学习笔记

    本文转载自:http://blog.csdn.net/tao_qq/article/details/49952229 学习dubbo,开始做一些笔记. 1> 启动dubbo-admin模块的时候 ...

  9. Dubbo学习笔记(二) Dubbo的基本配置

    Check启动检查 根据之前的学习,我们简单理解的Dubbo远程调用的基本流程,服务提供者注册到注册中心,然后服务消费者通过监听注册中心达到远程调用的目的,那么如果注册中心中没有消费者对应的接口会怎么 ...

随机推荐

  1. Solaris设备管理

    接手一台服务器,如何了解它的软硬件配置 数据库可以装在裸设备上,何为裸设备 知识点: 内核 驱动程序 设备命名 设备访问方式 磁盘的管理 内核: 指挥硬件干活的工具,shell翻译官,将人类语言翻译为 ...

  2. 【足迹C++primer】39、动态内存与智能指针(3)

    动态内存与智能指针(3) /** * 功能:动态内存与智能指针 * 时间:2014年7月8日15:33:58 * 作者:cutter_point */ #include<iostream> ...

  3. C语言-多重背包问题

    多重背包问题 问题:有N种物品和一个容量为V的背包.第i种物品最多有n[i]件可用,每件费用是c[i],价值是w[i].求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大. 分 ...

  4. 最新研发的基于Java的高速开发平台

    可自我扩展的智能开发平台       在开发平台设计过程中,联科研发部一開始就希望能研发一套智能开发机制能自己开发自己的平台-即一个能自我修复和自我扩展的开发平台.这个开发平台不但能开发其它应用还能不 ...

  5. HDU1009_FatMouse&#39; Trade【贪心】【水题】

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. Java Web工作原理(转载)

    知识要点: 1.HTTP协议 2.web服务器的缺陷及其解决方案 3.对Servlet的认识 4.Servlet的主要任务 5.web容器对Servlet的支持包括的内容 HTTP协议---(Hype ...

  7. Android 开发之static引发的冤案

    前段时间在android手机系统上开发一个小东西,先介绍一下他吧: 就是当手指点击屏幕不论什么地方的时候会出现点击的特效,就是在你点击屏幕的地方会出现各种效果,比方:雪花纷飞;出现五彩的肥皂泡:鲜花盛 ...

  8. please add a 'mainClass’ property

    when build an spring project with this command: mvn spring-boot:run there will may show an error mes ...

  9. 简单监控网站访问是否正常的shell脚本,邮件报警。网站恢复后继续运行。

    #!/bin/bash # 使用curl检查网页是否可以正常访问,如果无法访问则发邮件. SITE=crm.bjzgjh.com PROT=80 URL="http://$SITE:$PRO ...

  10. Qtree3

    题目描述 给出N个点的一棵树(N-1条边),节点有白有黑,初始全为白 有两种操作: 0 i : 改变某点的颜色(原来是黑的变白,原来是白的变黑) 1 v : 询问1到v的路径上的第一个黑点,若无,输出 ...