spring 整合dubbo 测试搭建
2016-03-21 14:51
489 查看
zookeeper:
<!-- zookeeper工具包 --> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.3.5</version> </dependency> <!-- zookeeper 第三方client --> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.7</version> </dependency>
dubbo:
<!-- dubbo --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.4.9</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> </exclusions> </dependency>
junit
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.1.7.RELEASE</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</versi 4000 on> </dependency>
package com.konglingfu.dubbo; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.xinnet.app.nofc.api.NewOfficeAPI; import com.xinnet.app.nofc.vo.NewOfficeVO; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:spring-dubbo.xml") public class DubboTest extends AbstractJUnit4SpringContextTests { @Autowired private NewOfficeAPI newOffice; @Test public void testDubbo(){ NewOfficeVO newOfficeVO = new NewOfficeVO(); newOfficeVO.setProductCode("AE0363421893383816"); newOfficeVO.setServiceCode("A75906223276350"); newOfficeVO.setGoodCode("63324082302807"); newOfficeVO.setGoodsType("01"); newOfficeVO.setServiceType("01");//服务状态 开通 续费 升级 停止 newOfficeVO.setAgentCode("hy439009"); newOfficeVO.setYear(5D); newOfficeVO.setUserNumbers("120"); newOfficeVO.setCompanyName("xinnent"); newOfficeVO.setAccount("hy439009"); newOfficeVO.setMemberName("xingzejiang"); newOfficeVO.setEmail("konglingfu@xinnet.com"); newOfficeVO.setMobile("18210568873"); newOfficeVO.setEdition("standard"); String result = newOffice.openService(newOfficeVO); System.out.println(result); } @Test public void testDubbo1(){ List<NewOfficeVO> list = newOffice.getNewOfficeByAgentCode("hy439009"); for(NewOfficeVO vo:list){ System.out.println(vo.toString()); } } }
consumer-nofc.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:reference id="newOffice" interface="com.xinnet.app.nofc.api.NewOfficeAPI" check="false" /> </beans>
spring-dubbo.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-4.2.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 提供方应用信息,用于计算依赖关系 --> <dubbo:application name="xinnetMemberFront-provider" /> <!-- 使用zookeeper注册中心暴露服务地址 --> <dubbo:registry protocol="zookeeper" address="IP地址:端口2181" /> <!-- 用dubbo协议在20880端口暴露服务 --> <dubbo:protocol name="dubbo" port="20882" /> <import resource="classpath*:consumer-*.xml" /> </beans>
相关文章推荐
- Java EE项目,通过127.0.0.1访问页面不变形,但是通过localhost访问页面变形
- Java将时间转换为UNIX时间戳
- 关于java的一些易错知识
- java transient关键字
- 排序算法-java
- 辗转相除法_欧几里得算法_java的实现(求最大公约数)
- java生成验证码
- 辗转相除法_欧几里得算法_java的实现(求最大公约数)
- 关于Java对象复制(Clone、深度Clone以及序列化与反序列化的使用)
- java xml文件的节点数展示
- java循环删除列表元素
- Eclipse中工程如何快速重新定位到新的SVN库?
- java安全(五)带秘钥的消息摘要算法——数字签名
- java常见内存溢出(OOM)解决方案
- 小白Java学习笔记(源自itcast-刘意java视频) 4000
- java中的访问控制权限
- Struts2中Action接收参数的方法
- [Java] Java中可变长参数的使用及注意事项
- springMVC—三种控制器controller
- java查找算法(五)--BFPRT查找算法