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,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.didispace</groupId>
<artifactId>compute-api-server</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>compute-api-server</name>
<description>Spring Boot project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- micro service api -->
<dependency>
<groupId>com.didispace</groupId>
<artifactId>compute-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<artifactId>spring</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
@@ -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 {
}
}