博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
dubbo 实战1
阅读量:5944 次
发布时间:2019-06-19

本文共 7256 字,大约阅读时间需要 24 分钟。

准备:先安装zookeeper,然后进入一下步骤

 

服务端

1.新建 maven项目

2.pom.xml 内容如下

4.0.0
com.demo
test
1.0-SNAPSHOT
org.springframework
spring-context
4.2.6.RELEASE
com.alibaba
dubbo
2.5.3
com.101tec
zkclient
0.9

3.在resource里新建 applicationContext.xml

4.新建IAnimal接口

package com.dubbo.controller;public interface IAnimal {    public  String say();}

5.IAnimal接口的实现

package com.dubbo.controller;import com.dubbo.controller.IAnimal;public class Animal implements IAnimal {    public  String say(){        return  "i am say 1";    }}

6.启动该应用(会注册到zookeeper)

import org.springframework.context.support.ClassPathXmlApplicationContext;public class Test1 {    public static void main(String[] args) throws Exception {        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml"});        context.start();        System.out.println(" app run ");        System.in.read(); // 按任意键退出    }}

启动后显示“ app run ” 则表示启动成功

 

客户端

1.新建maven 项目 dubbo-controller

2.pom.xml

4.0.0
com.dubbo
dubbo-controller
0.0.1-SNAPSHOT
war
dubbo-contoller
http://maven.apache.org
UTF-8
3.1.4.RELEASE
junit
junit
3.8.1
test
javax.servlet
javax.servlet-api
3.1.0
org.springframework
spring-context
${org.springframework.version}
org.springframework
spring-context-support
${org.springframework.version}
org.springframework
spring-web
${org.springframework.version}
org.springframework
spring-webmvc
${org.springframework.version}
org.codehaus.jackson
jackson-core-asl
1.9.12
org.codehaus.jackson
jackson-mapper-asl
1.9.12
net.sf.json-lib
json-lib
2.4
jdk15
com.alibaba
dubbo
2.5.3
spring
org.springframework
org.apache.zookeeper
zookeeper
3.3.6
log4j
log4j
log4j
log4j
1.2.16
com.github.sgroschupf
zkclient
0.1
com.dubbo
dubbo-api
0.0.1-SNAPSHOT
dubbo-controller
View Code

3.新建 applicationContext.xml

View Code

4.新建dubbo-config.xml

View Code

5.新建 spring-mvc.xml

View Code

6.新建接口 IAnimal

package com.dubbo.controller;public interface IAnimal {	 public  String say();}

 7.新建MyController

package com.dubbo.controller;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.ResponseBody;import com.dubbo.service.TestService;/** * controller * @author hwy * */@Controllerpublic class MyController {        @Autowired    private IAnimal testService;        @RequestMapping(value = "/test")    @ResponseBody    public String testSay(@RequestParam(value = "name",defaultValue = "") String name){        StringBuffer sb = new StringBuffer();        sb.append("aaa123456789001");    sb.append("Dubbo: ").append(testService.say());        return sb.toString();    }    }
View Code

8.web.xml

dubbo-controller
index.html
index.htm
index.jsp
dispatcher
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:applicationContext.xml
0
dispatcher
/

 

在Tomcat里运行该应用

访问:http://127.0.0.1:8080/dubbo-controller/test?name=hwy

源码:https://pan.baidu.com/s/1miBt9Ja

 

转载地址:http://tnwxx.baihongyu.com/

你可能感兴趣的文章
常用的脚本编程知识点
查看>>
XILINX_zynq_详解(6)
查看>>
计算机网络术语总结4
查看>>
新手小白 python之路 Day3 (string 常用方法)
查看>>
soapUI的简单使用(webservice接口功能测试)
查看>>
框架 Hibernate
查看>>
python-while循环
查看>>
手机端上传图片及java后台接收和ajaxForm提交
查看>>
【MSDN 目录】C#编程指南、C#教程、ASP.NET参考、ASP.NET 4、.NET Framework类库
查看>>
jquery 怎么触发select的change事件
查看>>
angularjs指令(二)
查看>>
(原創) 如何建立一个thread? (OS) (Linux) (C/C++) (C)
查看>>
<气场>读书笔记
查看>>
领域驱动设计,构建简单的新闻系统,20分钟够吗?
查看>>
web安全问题分析与防御总结
查看>>
React 组件通信之 React context
查看>>
ZooKeeper 可视化监控 zkui
查看>>
Linux下通过配置Crontab实现进程守护
查看>>
ios 打包上传Appstore 时报的错误 90101 90149
查看>>
Oracle推出轻量级Java微服务框架Helidon
查看>>