diff --git a/Chapter9-2-1/compute-service/pom.xml b/Chapter9-2-1/compute-service/pom.xml
new file mode 100644
index 0000000..89aed4d
--- /dev/null
+++ b/Chapter9-2-1/compute-service/pom.xml
@@ -0,0 +1,83 @@
+
+
+ 4.0.0
+
+ com.didispace
+ compute-service
+ 1.0.0
+ jar
+
+ compute-service
+ Spring Boot project
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 1.3.2.RELEASE
+
+
+
+
+ UTF-8
+ 1.8
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+ com.alibaba
+ dubbo
+ 2.5.3
+
+
+ spring
+ org.springframework
+
+
+
+
+
+ org.apache.zookeeper
+ zookeeper
+ 3.4.6
+
+
+ org.slf4j
+ slf4j-log4j12
+
+
+ log4j
+ log4j
+
+
+
+
+
+ com.github.sgroschupf
+ zkclient
+ 0.1
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
\ No newline at end of file
diff --git a/Chapter9-2-1/compute-service/src/main/java/com/didispace/Application.java b/Chapter9-2-1/compute-service/src/main/java/com/didispace/Application.java
new file mode 100644
index 0000000..4742e52
--- /dev/null
+++ b/Chapter9-2-1/compute-service/src/main/java/com/didispace/Application.java
@@ -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();
+ }
+
+}
diff --git a/Chapter9-2-1/compute-service/src/main/java/com/didispace/service/ComputeService.java b/Chapter9-2-1/compute-service/src/main/java/com/didispace/service/ComputeService.java
new file mode 100644
index 0000000..327ab16
--- /dev/null
+++ b/Chapter9-2-1/compute-service/src/main/java/com/didispace/service/ComputeService.java
@@ -0,0 +1,10 @@
+package com.didispace.service;
+
+/**
+ * Created by zhaiyc on 2016/7/14.
+ */
+public interface ComputeService {
+
+ Integer add(int a, int b);
+
+}
diff --git a/Chapter9-2-1/compute-service/src/main/java/com/didispace/service/impl/ComputeServiceImpl.java b/Chapter9-2-1/compute-service/src/main/java/com/didispace/service/impl/ComputeServiceImpl.java
new file mode 100644
index 0000000..3027859
--- /dev/null
+++ b/Chapter9-2-1/compute-service/src/main/java/com/didispace/service/impl/ComputeServiceImpl.java
@@ -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;
+ }
+
+}
diff --git a/Chapter9-2-1/compute-service/src/main/resources/application.properties b/Chapter9-2-1/compute-service/src/main/resources/application.properties
new file mode 100644
index 0000000..27fa322
--- /dev/null
+++ b/Chapter9-2-1/compute-service/src/main/resources/application.properties
@@ -0,0 +1,4 @@
+#ZooKeeper
+dubbo.registry.address=localhost:2181
+
+logging.level.root=DEBUG
\ No newline at end of file
diff --git a/Chapter9-2-1/compute-service/src/main/resources/dubbo.xml b/Chapter9-2-1/compute-service/src/main/resources/dubbo.xml
new file mode 100644
index 0000000..02491d7
--- /dev/null
+++ b/Chapter9-2-1/compute-service/src/main/resources/dubbo.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Chapter9-2-1/pom.xml b/Chapter9-2-1/consumer/pom.xml
similarity index 72%
rename from Chapter9-2-1/pom.xml
rename to Chapter9-2-1/consumer/pom.xml
index 1c3d697..3d6fea0 100644
--- a/Chapter9-2-1/pom.xml
+++ b/Chapter9-2-1/consumer/pom.xml
@@ -4,11 +4,11 @@
4.0.0
com.didispace
- Chapter9-2-1
+ consumer
1.0.0
jar
- Chapter9-2-1
+ consumer
Spring Boot project
@@ -29,21 +29,21 @@
spring-boot-starter
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
org.springframework.boot
spring-boot-starter-test
test
-
- org.springframework.boot
- spring-boot-starter-web
-
-
com.alibaba
dubbo
- 2.4.9
+ 2.5.3
spring
@@ -52,6 +52,28 @@
+
+ org.apache.zookeeper
+ zookeeper
+ 3.4.6
+
+
+ org.slf4j
+ slf4j-log4j12
+
+
+ log4j
+ log4j
+
+
+
+
+
+ com.github.sgroschupf
+ zkclient
+ 0.1
+
+
diff --git a/Chapter9-2-1/src/main/java/com/didispace/Application.java b/Chapter9-2-1/consumer/src/main/java/com/didispace/Application.java
similarity index 58%
rename from Chapter9-2-1/src/main/java/com/didispace/Application.java
rename to Chapter9-2-1/consumer/src/main/java/com/didispace/Application.java
index 8281fca..017ffc6 100644
--- a/Chapter9-2-1/src/main/java/com/didispace/Application.java
+++ b/Chapter9-2-1/consumer/src/main/java/com/didispace/Application.java
@@ -1,14 +1,19 @@
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 {
- public static void main(String[] args) {
+ public static void main(String[] args) throws InterruptedException {
SpringApplication.run(Application.class, args);
}
diff --git a/Chapter9-2-1/consumer/src/main/java/com/didispace/service/ComputeService.java b/Chapter9-2-1/consumer/src/main/java/com/didispace/service/ComputeService.java
new file mode 100644
index 0000000..327ab16
--- /dev/null
+++ b/Chapter9-2-1/consumer/src/main/java/com/didispace/service/ComputeService.java
@@ -0,0 +1,10 @@
+package com.didispace.service;
+
+/**
+ * Created by zhaiyc on 2016/7/14.
+ */
+public interface ComputeService {
+
+ Integer add(int a, int b);
+
+}
diff --git a/Chapter9-2-1/consumer/src/main/java/com/didispace/web/ComputeController.java b/Chapter9-2-1/consumer/src/main/java/com/didispace/web/ComputeController.java
new file mode 100644
index 0000000..3d8f5ca
--- /dev/null
+++ b/Chapter9-2-1/consumer/src/main/java/com/didispace/web/ComputeController.java
@@ -0,0 +1,24 @@
+package com.didispace.web;
+
+import com.didispace.service.ComputeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * Created by zhaiyc on 2016/7/14.
+ */
+@RestController
+public class ComputeController {
+
+ @Autowired
+ private ComputeService computeService;
+
+ @RequestMapping(value = "/add", method = RequestMethod.GET)
+ public String add(@RequestParam Integer a, @RequestParam Integer b) {
+ return String.valueOf(a + b);
+ }
+
+}
diff --git a/Chapter9-2-1/consumer/src/main/resources/application.properties b/Chapter9-2-1/consumer/src/main/resources/application.properties
new file mode 100644
index 0000000..c9ce027
--- /dev/null
+++ b/Chapter9-2-1/consumer/src/main/resources/application.properties
@@ -0,0 +1,5 @@
+#ZooKeeper
+dubbo.registry.address=localhost:2181
+
+
+logging.level.root=DEBUG
\ No newline at end of file
diff --git a/Chapter9-2-1/consumer/src/main/resources/dubbo.xml b/Chapter9-2-1/consumer/src/main/resources/dubbo.xml
new file mode 100644
index 0000000..4760bfa
--- /dev/null
+++ b/Chapter9-2-1/consumer/src/main/resources/dubbo.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Chapter9-2-1/consumer/src/test/java/com/didispace/ApplicationTests.java b/Chapter9-2-1/consumer/src/test/java/com/didispace/ApplicationTests.java
new file mode 100644
index 0000000..244658f
--- /dev/null
+++ b/Chapter9-2-1/consumer/src/test/java/com/didispace/ApplicationTests.java
@@ -0,0 +1,24 @@
+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;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringApplicationConfiguration(classes = Application.class)
+@WebAppConfiguration
+public class ApplicationTests {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void getHello() throws Exception {
+ }
+
+}
diff --git a/Chapter9-2-1/src/main/resources/application.properties b/Chapter9-2-1/src/main/resources/application.properties
deleted file mode 100644
index e69de29..0000000
diff --git a/Chapter9-2-1/src/main/resources/dubbo.xml b/Chapter9-2-1/src/main/resources/dubbo.xml
deleted file mode 100644
index 931723f..0000000
--- a/Chapter9-2-1/src/main/resources/dubbo.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter9-2-1/src/test/java/com/didispace/ApplicationTests.java b/Chapter9-2-1/src/test/java/com/didispace/ApplicationTests.java
deleted file mode 100644
index 5d70be9..0000000
--- a/Chapter9-2-1/src/test/java/com/didispace/ApplicationTests.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.didispace;
-
-import com.didispace.web.HelloController;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.boot.test.SpringApplicationConfiguration;
-import org.springframework.http.MediaType;
-import org.springframework.mock.web.MockServletContext;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.test.context.web.WebAppConfiguration;
-import org.springframework.test.web.servlet.MockMvc;
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
-import org.springframework.test.web.servlet.setup.MockMvcBuilders;
-
-import static org.hamcrest.Matchers.equalTo;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@SpringApplicationConfiguration(classes = MockServletContext.class)
-@WebAppConfiguration
-public class ApplicationTests {
-
- private MockMvc mvc;
-
- @Before
- public void setUp() throws Exception {
- mvc = MockMvcBuilders.standaloneSetup(new HelloController()).build();
- }
-
- @Test
- public void getHello() throws Exception {
- mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk())
- .andExpect(content().string(equalTo("Hello World")));
- }
-
-}