安装

一、本地服务
 
  1、定义服务接口: (该接口需单独打包,在服务提供方和消费方共享)
public interface CustomerService {
public String getName();
}

2、在服务提供方实现接口:(对服务消费方隐藏实现)

public class CustomerServiceImpl implements CustomerService{
@Override
public String getName() {
System.out.print("我打印");
return "打印结果";
}
}

3、然后引入dubbo的几个包

     dubbo-2.5.3.jar
     log4j.jar
     netty-3.5.7.Final.jar
     slf4j.jar
     slf4j-log4j.jar
     zkclient.jar
     zookeeper.jar
 
  4、用Spring配置声明暴露服务:
   
      新建applicationProvider.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 ">
<!-- 具体的实现bean -->
<bean id="demoService" class="com.jinbin.service.customer.CustomerServiceImpl" />
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="xixi_provider" />
<!-- 使用multicast广播注册中心暴露服务地址
<dubbo:registry address="multicast://localhost:1234" />-->
<!-- 使用zookeeper注册中心暴露服务地址 -->
<dubbo:registry address="zookeeper://192.168.1.3:2181" />
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.jinbin.service.customer.CustomerService" ref="demoService" />
</beans>
我这里暴露服务器的地址交由zookeeper来管理的,使用者首先先要安装zookeeper应用才能使用此功能,相关安装步骤请参看相关博文
5、加载Spring配置,并调用远程服务:(也可以使用IoC注入)
public class DubooProvider {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[]{"applicationProvider.xml"});
context.start();
System.out.println("Press any key to exit.");
try {
System.in.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

并且启动,使其进入启动状态。

 
以上为服务器提供者的完整步骤,功能接口都已经写好,下面我们就开始怎么远程调用
 
二、服务消费者
 
 1、新建个配置文件applicationConsumer.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 ">
<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="consumer-of-helloworld-app" />
<!-- 使用multicast广播注册中心暴露发现服务地址 -->
<dubbo:registry protocol="zookeeper" address="zookeeper://192.168.1.3:2181" />
<!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:reference id="demoService" interface="com.jinbin.service.customer.CustomerService" />
</beans>
为了在web中使用,我们在web.xml中配置在spring启动读取过程中
   <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application.xml /WEB-INF/applicationConsumer.xml</param-value>
</context-param>

2、接口调用

 
  调用过程很简单,先把接口文件打成jar包,然后在此工程中进行引用
 
 在springmvc调用程序如下:
@Autowired CustomerService demoService ;	 
  @RequestMapping(value="duboo1")
public void duboo1(){
demoService.getName();
}

即可执行成功

 
三、dubbo-admin的使用
 
 
    下载dubbo-admin-2.5.3.war
 
    将其放到tomcat下面,配置dubbo.properties,
vi
webapps/ROOT/WEB-INF/dubbo.properties
dubbo.properties
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest

修改zookeeper的URL和端口

     

    启动:

./bin/startup.sh

dubbo与spring mvc的更多相关文章

  1. 开发步骤Dubbo、spring mvc、springboot、SSM开发步骤

    一.Dubbo开发步骤: 链接:https://pan.baidu.com/s/1pMPO1kf 密码:9zaa 第一: 1.创建consumer工程2.在pom.xml文件下添加配置3.添加appl ...

  2. 开发步骤Dubbo、spring mvc、springboot、SSM整合开发步骤

    一.Dubbo开发步骤: 链接:https://pan.baidu.com/s/1pMPO1kf 密码:9zaa 第一: 1.创建consumer工程2.在pom.xml文件下添加配置3.添加appl ...

  3. 基于Vue+Spring MVC+MyBatis+Shiro+Dubbo开发的分布式后台管理系统

    本文项目代码: 服务端:https://github.com/lining90567/dubbo-demo-server 前端:https://github.com/lining90567/dubbo ...

  4. 0.从零开始搭建spring mvc + mybatis + memcached+ dubbo\zookper的maven项目

    1.首先创建maven 项目,配置相关pom信息 2.配置spring mvc 4, 测试,提交代码 3.引入配置mybatis3,测试,提交代码 4.配置事务,测试,提交代码 5.配置memcach ...

  5. dubbo,gradle,spring build from source

    https://github.com/alibaba/dubbo http://www.csdn.net/article/2012-11-13/2811827-alibaba-Dubbo-Distri ...

  6. dubbo+zookeeper+spring+springMVC+mybatis的使用

    读前声明:由于本人水平有限,有错误或者描述不恰当的地方请指出来,勿喷!第一次写博客. 源码下载链接:http://files.cnblogs.com/files/la-tiao-jun-blog/du ...

  7. java企业架构 spring mvc +mybatis + KafKa+Flume+Zookeeper

    声明:该框架面向企业,是大型互联网分布式企业架构,后期会介绍linux上部署高可用集群项目. 项目基础功能截图(自提供了最小部分)      平台简介        Jeesz是一个分布式的框架,提供 ...

  8. Spring MVC简单原理

    Spring MVC原理 针对有Java Web基础.Spring基础和Spring MVC使用经验者. 前言 目前基于Java的web后端,Spring生态应该是比较常见了.虽然现在流行前后端分离, ...

  9. spring MVC框架入门(外加SSM整合)

    spring MVC框架 一.什么是sping MVC Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面.Spring 框架提供了构建 W ...

随机推荐

  1. MYSQL SHOW VARIABLES简介

    原文地址:http://www.2cto.com/database/201108/100546.html mysqld服务器维护两种变量.全局变量影响服务器的全局操作.会话变量影响具体客户端连接相关操 ...

  2. SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-006- 使用thymeleaf(TemplateResolver、SpringTemplateEngine、ThymeleafViewResolver、th:include、th:object、th:field="*{firstName}")

    一.在Spring中使用thymeleaf的步骤 1.配置 In order to use Thymeleaf with Spring, you’ll need to configure three ...

  3. Android 国际化图片资源文件

    国际化 与字符串国际相似,在 res 下新建 drawable-zh 文件夹,存放中文环境下的图片        新建 drawable-en 作为英语环境下的图片        在 eclipse ...

  4. FRM-40401 No changes to save error

    FAQ: I have updated a table from the form and written a update statement in the when-button-pressed ...

  5. VM8下安装Mac OS X 10.7

    下载Mac OS X  10.7 安装包http://115.com/file/clj1iu8m#            下载HJMac http://115.com/file/cljyu1rh#   ...

  6. 【转】Android 源码编译make的错误处理--不错

    原文网址:http://blog.csdn.net/ithomer/article/details/6977386 Android源码下载:官方下载 或参考android源码下载方式 Android编 ...

  7. 【转】JNI学习积累之一 ---- 常用函数大全

    原文网址:http://blog.csdn.net/qinjuning/article/details/7595104 本文原创,转载请注明出处:http://blog.csdn.net/qinjun ...

  8. Oracle 新增表空间文件

    ALTER TABLESPACE users ADD DATAFILE 'D:/oracle/oradata/orcl/users.dbf' SIZE 500M AUTOEXTEND ON NEXT ...

  9. selenium使用整理

    学习selenium自动化有一段时间了,今天一位自动化测试大侠给了我指导.如下: 第一步,先用selenium的固定脚本把手工测试的流程写成脚本 eg: driver.FindElement(By.I ...

  10. Asp.Net MVC4新特性指南(2):新特性介绍

       上一章讲解了最基本的MVC4说明.今天就介绍下几种新特性的使用例子:   就当大家有MVC3的基础了.在这个基础上在看下面的介绍就容易多了.1.Web API MVC4包括一个更好的解决方案:A ...