Skip to content

Commit 90dcb48

Browse files
dyc87112zhaiyongchao
authored and
zhaiyongchao
committedJul 14, 2016
spring boot与dubbo的API依赖管理
1 parent aae309d commit 90dcb48

File tree

15 files changed

+413
-0
lines changed

15 files changed

+413
-0
lines changed
 
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>compute-api-server</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>compute-api-server</name>
12+
<description>Spring Boot project</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.3.2.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
28+
<!-- spring boot -->
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter</artifactId>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-test</artifactId>
37+
<scope>test</scope>
38+
</dependency>
39+
40+
<!-- micro service api -->
41+
<dependency>
42+
<groupId>com.didispace</groupId>
43+
<artifactId>compute-api</artifactId>
44+
<version>1.0-SNAPSHOT</version>
45+
</dependency>
46+
47+
<!-- dubbo -->
48+
<dependency>
49+
<groupId>com.alibaba</groupId>
50+
<artifactId>dubbo</artifactId>
51+
<version>2.5.3</version>
52+
<exclusions>
53+
<exclusion>
54+
<artifactId>spring</artifactId>
55+
<groupId>org.springframework</groupId>
56+
</exclusion>
57+
</exclusions>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>org.apache.zookeeper</groupId>
62+
<artifactId>zookeeper</artifactId>
63+
<version>3.4.6</version>
64+
<exclusions>
65+
<exclusion>
66+
<groupId>org.slf4j</groupId>
67+
<artifactId>slf4j-log4j12</artifactId>
68+
</exclusion>
69+
<exclusion>
70+
<groupId>log4j</groupId>
71+
<artifactId>log4j</artifactId>
72+
</exclusion>
73+
</exclusions>
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>com.github.sgroschupf</groupId>
78+
<artifactId>zkclient</artifactId>
79+
<version>0.1</version>
80+
</dependency>
81+
82+
</dependencies>
83+
84+
<build>
85+
<plugins>
86+
<plugin>
87+
<groupId>org.springframework.boot</groupId>
88+
<artifactId>spring-boot-maven-plugin</artifactId>
89+
</plugin>
90+
</plugins>
91+
</build>
92+
93+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.didispace;
2+
3+
import org.apache.log4j.Logger;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.context.ApplicationContext;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.annotation.ImportResource;
9+
10+
import java.util.concurrent.CountDownLatch;
11+
12+
@SpringBootApplication
13+
@ImportResource({"classpath:dubbo.xml"})
14+
public class Application {
15+
16+
private static final Logger logger = Logger.getLogger(Application.class);
17+
18+
@Bean
19+
public CountDownLatch closeLatch() {
20+
return new CountDownLatch(1);
21+
}
22+
23+
public static void main(String[] args) throws InterruptedException {
24+
ApplicationContext ctx = SpringApplication.run(Application.class, args);
25+
logger.info("项目启动!");
26+
CountDownLatch closeLatch = ctx.getBean(CountDownLatch.class);
27+
closeLatch.await();
28+
}
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.didispace.service.impl;
2+
3+
import com.didispace.service.ComputeService;
4+
5+
/**
6+
* Created by zhaiyc on 2016/7/14.
7+
*/
8+
public class ComputeServiceImpl implements ComputeService {
9+
10+
@Override
11+
public Integer add(int a, int b) {
12+
return a + b;
13+
}
14+
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ZooKeeper
2+
dubbo.registry.address=localhost:2181
3+
4+
logging.level.root=DEBUG
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
6+
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
7+
8+
<!-- 提供方应用信息,用于计算依赖关系 -->
9+
<dubbo:application name="compute-service" />
10+
11+
<!-- 注册中心服务地址 -->
12+
<dubbo:registry id="zookeeper" protocol="zookeeper" address="${dubbo.registry.address}" />
13+
14+
<!-- 用dubbo协议在30001 -->
15+
<dubbo:protocol name="dubbo" port="30001" dispather="all" threadpool="cached" threads="5000"/>
16+
17+
<!-- 声明需要暴露的服务接口 -->
18+
<dubbo:service interface="com.didispace.service.ComputeService" ref="computeService"
19+
version="1.0" registry="zookeeper" owner="shp"/>
20+
21+
<!-- 具体服务接口的实现 -->
22+
<bean id="computeService" class="com.didispace.service.impl.ComputeServiceImpl" />
23+
24+
</beans>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.didispace;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.springframework.boot.test.SpringApplicationConfiguration;
7+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
8+
9+
10+
@RunWith(SpringJUnit4ClassRunner.class)
11+
@SpringApplicationConfiguration(classes = Application.class)
12+
public class ApplicationTests {
13+
14+
@Before
15+
public void setUp() throws Exception {
16+
}
17+
18+
@Test
19+
public void getHello() throws Exception {
20+
}
21+
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.didispace</groupId>
9+
<artifactId>compute-service</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>compute-api</artifactId>
14+
<name>compute-api</name>
15+
<packaging>jar</packaging>
16+
17+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.didispace.service;
2+
3+
/**
4+
* Created by zhaiyc on 2016/7/14.
5+
*/
6+
public interface ComputeService {
7+
8+
Integer add(int a, int b);
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.didispace.service.impl;
2+
3+
import com.didispace.service.ComputeService;
4+
5+
/**
6+
* Created by zhaiyc on 2016/7/14.
7+
*/
8+
public class ComputeServiceImpl implements ComputeService {
9+
10+
@Override
11+
public Integer add(int a, int b) {
12+
return a + b;
13+
}
14+
15+
}

‎Chapter9-2-2/compute-service/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.didispace</groupId>
8+
<artifactId>compute-service</artifactId>
9+
<packaging>pom</packaging>
10+
<version>1.0-SNAPSHOT</version>
11+
12+
<modules>
13+
<module>compute-api</module>
14+
<module>compute-api-server</module>
15+
</modules>
16+
17+
<properties>
18+
<maven.test.skip>true</maven.test.skip>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
<java.version>1.7</java.version>
21+
<maven.compiler.source>1.7</maven.compiler.source>
22+
<maven.compiler.target>1.7</maven.compiler.target>
23+
</properties>
24+
25+
26+
</project>

‎Chapter9-2-2/consumer/pom.xml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>consumer</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>consumer</name>
12+
<description>Spring Boot project</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.3.2.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter</artifactId>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-web</artifactId>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-test</artifactId>
40+
<scope>test</scope>
41+
</dependency>
42+
43+
<!-- micro service api -->
44+
<dependency>
45+
<groupId>com.didispace</groupId>
46+
<artifactId>compute-api</artifactId>
47+
<version>1.0-SNAPSHOT</version>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>com.alibaba</groupId>
52+
<artifactId>dubbo</artifactId>
53+
<version>2.5.3</version>
54+
<exclusions>
55+
<exclusion>
56+
<artifactId>spring</artifactId>
57+
<groupId>org.springframework</groupId>
58+
</exclusion>
59+
</exclusions>
60+
</dependency>
61+
62+
<dependency>
63+
<groupId>org.apache.zookeeper</groupId>
64+
<artifactId>zookeeper</artifactId>
65+
<version>3.4.6</version>
66+
<exclusions>
67+
<exclusion>
68+
<groupId>org.slf4j</groupId>
69+
<artifactId>slf4j-log4j12</artifactId>
70+
</exclusion>
71+
<exclusion>
72+
<groupId>log4j</groupId>
73+
<artifactId>log4j</artifactId>
74+
</exclusion>
75+
</exclusions>
76+
</dependency>
77+
78+
<dependency>
79+
<groupId>com.github.sgroschupf</groupId>
80+
<artifactId>zkclient</artifactId>
81+
<version>0.1</version>
82+
</dependency>
83+
84+
</dependencies>
85+
86+
<build>
87+
<plugins>
88+
<plugin>
89+
<groupId>org.springframework.boot</groupId>
90+
<artifactId>spring-boot-maven-plugin</artifactId>
91+
</plugin>
92+
</plugins>
93+
</build>
94+
95+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.didispace;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.context.annotation.ImportResource;
6+
7+
@SpringBootApplication
8+
@ImportResource({"classpath:dubbo.xml"})
9+
public class Application {
10+
11+
public static void main(String[] args) throws InterruptedException {
12+
SpringApplication.run(Application.class, args);
13+
}
14+
15+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#ZooKeeper
2+
dubbo.registry.address=localhost:2181
3+
4+
5+
logging.level.root=INFO

0 commit comments

Comments
 (0)
Please sign in to comment.