spring 整合dubbo 測試搭建
阿新 • • 發佈:2018-11-09
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("[email protected]");
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>