spring 整合dubbo 测试搭建

来源:互联网 发布:oracle数据字典 编辑:程序博客网 时间:2024/05/16 17:39

项目结构图
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</version></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>
0 0
原创粉丝点击