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,30 @@
package com.didispace;
import org.apache.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import java.util.concurrent.CountDownLatch;
@SpringBootApplication
@ImportResource({"classpath:dubbo.xml"})
public class Application {
private static final Logger logger = Logger.getLogger(Application.class);
@Bean
public CountDownLatch closeLatch() {
return new CountDownLatch(1);
}
public static void main(String[] args) throws InterruptedException {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
logger.info("项目启动!");
CountDownLatch closeLatch = ctx.getBean(CountDownLatch.class);
closeLatch.await();
}
}
@@ -0,0 +1,15 @@
package com.didispace.service.impl;
import com.didispace.service.ComputeService;
/**
* Created by zhaiyc on 2016/7/14.
*/
public class ComputeServiceImpl implements ComputeService {
@Override
public Integer add(int a, int b) {
return a + b;
}
}
@@ -0,0 +1,4 @@
#ZooKeeper
dubbo.registry.address=localhost:2181
logging.level.root=DEBUG
@@ -0,0 +1,24 @@
<?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="compute-service" />
<!-- 注册中心服务地址 -->
<dubbo:registry id="zookeeper" protocol="zookeeper" address="${dubbo.registry.address}" />
<!-- 用dubbo协议在30001 -->
<dubbo:protocol name="dubbo" port="30001" dispather="all" threadpool="cached" threads="5000"/>
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.didispace.service.ComputeService" ref="computeService"
version="1.0" registry="zookeeper" owner="shp"/>
<!-- 具体服务接口的实现 -->
<bean id="computeService" class="com.didispace.service.impl.ComputeServiceImpl" />
</beans>
@@ -0,0 +1,22 @@
package com.didispace;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
public class ApplicationTests {
@Before
public void setUp() throws Exception {
}
@Test
public void getHello() throws Exception {
}
}