本地Dubbo项目搭建测试例子.docx
- 文档编号:2892346
- 上传时间:2022-11-16
- 格式:DOCX
- 页数:45
- 大小:4.22MB
本地Dubbo项目搭建测试例子.docx
《本地Dubbo项目搭建测试例子.docx》由会员分享,可在线阅读,更多相关《本地Dubbo项目搭建测试例子.docx(45页珍藏版)》请在冰豆网上搜索。
本地Dubbo项目搭建测试例子
一:
zookeeper的下载及配置:
一:
zookeeper下载:
下载地址:
点击zookeeper-3.4.6.tar.gz下载即可!
二:
zookeeper配置:
Zookeeper下载后的目录,如图:
1)配置路径:
/conf目录下面的zoo_sample.cfg复制并修改为zoo.cfg
此处名称必须是zoo.cfg否则启动文件找不到会出现闪退现象。
tickTime:
Zookeeper服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个tickTime时间就会发送一个心跳。
tickTime以毫秒为单位。
initLimit:
集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
syncLimit:
集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)。
dataDir:
Zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。
dataLogDir:
Zookeeper保存日志文件的目录。
clientPort:
客户端连接Zookeeper服务器的端口,Zookeeper会监听这个端口,接受客户端的访问请求。
==========================代码如下=====================================
#Thenumberofmillisecondsofeachtick
tickTime=2000
#Thenumberofticksthattheinitial
#synchronizationphasecantake
initLimit=10
#Thenumberofticksthatcanpassbetween
#sendingarequestandgettinganacknowledgement
syncLimit=5
#thedirectorywherethesnapshotisstored.
#donotuse/tmpforstorage,/tmphereisjust
#examplesakes.
dataDir=/data
#theportatwhichtheclientswillconnect
clientPort=2181
#themaximumnumberofclientconnections.
#increasethisifyouneedtohandlemoreclients
#maxClientCnxns=60
#
#Besuretoreadthemaintenancesectionofthe
#administratorguidebeforeturningonautopurge.
#
#http:
//zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
#ThenumberofsnapshotstoretainindataDir
#autopurge.snapRetainCount=3
#Purgetaskintervalinhours
#Setto"0"todisableautopurgefeature
#autopurge.purgeInterval=1
即可。
2)路径修改
#Thenumberofmillisecondsofeachtick
tickTime=2000
#Thenumberofticksthattheinitial
#synchronizationphasecantake
initLimit=10
#Thenumberofticksthatcanpassbetween
#sendingarequestandgettinganacknowledgement
syncLimit=5
#thedirectorywherethesnapshotisstored.
#donotuse/tmpforstorage,/tmphereisjust
#examplesakes.
dataDir=C:
/Users/issuser/Desktop/service1/data
dataLogDir=C:
/Users/issuser/Desktop/service1/log
#theportatwhichtheclientswillconnect
clientPort=2183
#themaximumnumberofclientconnections.
#increasethisifyouneedtohandlemoreclients
#maxClientCnxns=60
#
#Besuretoreadthemaintenancesectionofthe
#administratorguidebeforeturningonautopurge.
#
#http:
//zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
#ThenumberofsnapshotstoretainindataDir
#autopurge.snapRetainCount=3
#Purgetaskintervalinhours
#Setto"0"todisableautopurgefeature
#autopurge.purgeInterval=1
二:
创建项目
一:
做服务端:
1)创建一个web项目:
DubboZookeeper作为服务端。
2)定义一个实体类:
User
publicclassUser{
@Override
publicStringtoString(){
return"User[name="+name+",age="+age+",sex="+sex+"]";
}
privateStringname;
privateintage;
privateStringsex;
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicintgetAge(){
returnage;
}
publicvoidsetAge(intage){
this.age=age;
}
publicStringgetSex(){
returnsex;
}
publicvoidsetSex(Stringsex){
this.sex=sex;
}
}
3)定义一个service接口:
DemoService
publicinterfaceDemoService{
StringsayHello(Stringname);
publicListgetUsers();
}
4)定义一个service接口的实现类,DemoServiceImpl
publicclassDemoServiceImplimplementsDemoService{
@Override
publicStringsayHello(Stringname){
return"Hello"+name;
}
@Override
publicListgetUsers(){
Listlist=newArrayList();
Useru1=newUser();
u1.setName("jack");
u1.setAge(20);
u1.setSex("男");
Useru2=newUser();
u2.setName("tom");
u2.setAge(21);
u2.setSex("女");
Useru3=newUser();
u3.setName("rose");
u3.setAge(19);
u3.setSex("女");
list.add(u1);
list.add(u2);
list.add(u3);
returnlist;
}
}
5)创建一个dao的测试类Provider:
(使用JUnit测试)
publicclassProvider{
@Before
publicvoidsetUp()throwsException{
}
@Test
publicvoidtestMain()throwsIOException{
ClassPathXmlApplicationContextcontext=newClassPathXmlApplicationContext(newString[]{"applicationContext.xml"});
context.start();
System.in.read();//按任意键退出
}
}
6)创建XML配置文件:
applicationContext.xml(注意:
此处的路径必须是项目的路径,能ctrl+鼠标点进去)
xmlversion="1.0"encoding="UTF-8"?
>
//www.springframework.org/schema/beans" xmlns: xsi="http: //www.w3.org/2001/XMLSchema-instance"xmlns: dubbo=" xsi: schemaLocation="http: //www.springframework.org/schema/beans http: //www.springframework.org/schema/beans/spring-beans.xsd "> --具体的实现bean-->
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 本地 Dubbo 项目 搭建 测试 例子
![提示](https://static.bdocx.com/images/bang_tan.gif)