spring boot与dubbo的API依赖管理

This commit is contained in:
程序猿DD
2016-07-14 14:52:05 +08:00
committed by zhaiyongchao
parent aae309df5a
commit 90dcb48bbb
15 changed files with 413 additions and 0 deletions
@@ -0,0 +1,15 @@
package com.didispace;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
@SpringBootApplication
@ImportResource({"classpath:dubbo.xml"})
public class Application {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(Application.class, args);
}
}
@@ -0,0 +1,5 @@
#ZooKeeper
dubbo.registry.address=localhost:2181
logging.level.root=INFO
@@ -0,0 +1,18 @@
<?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:application name="consumer" />
<!-- 注册中心服务地址 -->
<dubbo:registry id="zookeeper" protocol="zookeeper" address="${dubbo.registry.address}" />
<!-- 引用ComputeService服务-->
<dubbo:reference id="computeService" interface="com.didispace.service.ComputeService"
check="false" version="1.0" url="" registry="zookeeper" protocol="dubbo" timeout="15000"/>
</beans>
@@ -0,0 +1,24 @@
package com.didispace;
import com.didispace.service.ComputeService;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
public class ApplicationTests {
@Autowired
private ComputeService computeService;
@Test
public void testAdd() throws Exception {
Assert.assertEquals("compute-service:add", new Integer(3), computeService.add(1, 2));
}
}