diff --git a/TODO.md b/TODO.md
index aee7d7d..ee10756 100644
--- a/TODO.md
+++ b/TODO.md
@@ -37,7 +37,7 @@
- [ ] spring-boot-demo-urule(集成 urule 实现规则引擎)
- [ ] spring-boot-demo-activiti(集成 Activiti 实现流程控制引擎)
- [ ] spring-boot-demo-async(Spring boot 实现异步调用)
-- [ ] spring-boot-demo-dubbo(集成 dubbo)
+- [x] ~~spring-boot-demo-dubbo(集成 dubbo)~~
- [x] ~~spring-boot-demo-war(打包成war包)~~
- [x] ~~spring-boot-demo-elasticsearch(集成 ElasticSearch,使用原生操作 ES 的方式)~~
diff --git a/spring-boot-demo-dubbo-parent/.gitignore b/spring-boot-demo-dubbo-parent/.gitignore
new file mode 100644
index 0000000..82eca33
--- /dev/null
+++ b/spring-boot-demo-dubbo-parent/.gitignore
@@ -0,0 +1,25 @@
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
\ No newline at end of file
diff --git a/spring-boot-demo-dubbo-parent/README.md b/spring-boot-demo-dubbo-parent/README.md
new file mode 100644
index 0000000..d5c1851
--- /dev/null
+++ b/spring-boot-demo-dubbo-parent/README.md
@@ -0,0 +1,116 @@
+# spring-boot-demo-dubbo-parent
+
+依赖 [非官方的spring-boot-starter-dubbo](https://gitee.com/reger/spring-boot-starter-dubbo)
+
+更新 springboot 版本为 2.0.1.RELEASE
+
+本身是个父依赖,包含了3个 module
+
+| 名称 | 作用 |
+| :----------------------------------------------------------- | :-------------------------------------- |
+| [spring-boot-demo-dubbo-api](./spring-boot-demo-dubbo-api/pom.xml) | Spring Boot 与 Dubbo 整合抽取的服务接口 |
+| [spring-boot-demo-dubbo-provider](./spring-boot-demo-dubbo-provider/pom.xml) | Spring Boot 与 Dubbo 整合服务的提供方 |
+| [spring-boot-demo-dubbo-consumer](./spring-boot-demo-dubbo-consumer/pom.xml) | Spring Boot 与 Dubbo 整合服务的消费方 |
+
+### pom.xml
+
+```xml
+
+
+ * GreetController + *
+ * + * @package: com.xkcoding.springbootdemodubboconsumer.controller + * @description: GreetController + * @author: yangkai.shen + * @date: Created in 2018/4/17 下午5:29 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@RestController +@RequestMapping("/greet") +public class GreetController { + @Autowired + private GreetService greetService; + + @GetMapping("") + public String hello(@RequestParam String name) { + return greetService.greeting(name); + } +} +``` + +### GreetService.java + +```java +package com.xkcoding.springbootdemodubboconsumer.service; + +/** + *+ * GreetService + *
+ * + * @package: com.xkcoding.springbootdemodubboconsumer.service + * @description: GreetService + * @author: yangkai.shen + * @date: Created in 2018/4/17 下午5:30 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +public interface GreetService { + String greeting(String name); +} +``` + +### GreetServiceImpl.java + +代码中的 `@Service` 使用的是 `Spring` 的注解,而不是 `Dubbo` 的注解 + +代码中的 `@Inject` 可以替换成 `Dubbo` 提供的 `@Reference`,效果相同 + +```java +package com.xkcoding.springbootdemodubboconsumer.service.impl; + +import com.reger.dubbo.annotation.Inject; +import com.xkcoding.springbootdemodubboapi.service.HelloService; +import com.xkcoding.springbootdemodubboconsumer.service.GreetService; +import org.springframework.stereotype.Service; + +/** + *+ * GreetServiceImpl + *
+ * + * @package: com.xkcoding.springbootdemodubboconsumer.service.impl + * @description: GreetServiceImpl + * @author: yangkai.shen + * @date: Created in 2018/4/17 下午5:31 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Service +public class GreetServiceImpl implements GreetService { + @Inject + private HelloService helloService; + + @Override + public String greeting(String name) { + return helloService.hello(name); + } +} +``` + diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/pom.xml b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/pom.xml new file mode 100644 index 0000000..94bc2fb --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/pom.xml @@ -0,0 +1,35 @@ + ++ * GreetController + *
+ * + * @package: com.xkcoding.springbootdemodubboconsumer.controller + * @description: GreetController + * @author: yangkai.shen + * @date: Created in 2018/4/17 下午5:29 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@RestController +@RequestMapping("/greet") +public class GreetController { + @Autowired + private GreetService greetService; + + @GetMapping("") + public String hello(@RequestParam String name) { + return greetService.greeting(name); + } +} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/GreetService.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/GreetService.java new file mode 100644 index 0000000..bf1300f --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/GreetService.java @@ -0,0 +1,18 @@ +package com.xkcoding.springbootdemodubboconsumer.service; + +/** + *+ * GreetService + *
+ * + * @package: com.xkcoding.springbootdemodubboconsumer.service + * @description: GreetService + * @author: yangkai.shen + * @date: Created in 2018/4/17 下午5:30 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +public interface GreetService { + String greeting(String name); +} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/impl/GreetServiceImpl.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/impl/GreetServiceImpl.java new file mode 100644 index 0000000..d7599c0 --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/impl/GreetServiceImpl.java @@ -0,0 +1,30 @@ +package com.xkcoding.springbootdemodubboconsumer.service.impl; + +import com.reger.dubbo.annotation.Inject; +import com.xkcoding.springbootdemodubboapi.service.HelloService; +import com.xkcoding.springbootdemodubboconsumer.service.GreetService; +import org.springframework.stereotype.Service; + +/** + *+ * GreetServiceImpl + *
+ * + * @package: com.xkcoding.springbootdemodubboconsumer.service.impl + * @description: GreetServiceImpl + * @author: yangkai.shen + * @date: Created in 2018/4/17 下午5:31 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Service +public class GreetServiceImpl implements GreetService { + @Inject + private HelloService helloService; + + @Override + public String greeting(String name) { + return helloService.hello(name); + } +} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/resources/application.yml b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/resources/application.yml new file mode 100644 index 0000000..35642dd --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/resources/application.yml @@ -0,0 +1,14 @@ +server: + port: 9090 +spring: + dubbo: + application: + name: dubbo-consumer + base-package: com.xkcoding.springbootdemodubboconsumer.service # dubbo服务调用者所在的包 + registry: + address: 127.0.0.1 # zookeeper注册中心的地址 + port: 2181 # zookeeper注册中心的端口 + consumer: + timeout: 1000 + check: true # 服务启动时检查被调用服务是否可用 + retries: 2 \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/test/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplicationTests.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/test/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplicationTests.java new file mode 100644 index 0000000..cbd6b54 --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/test/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplicationTests.java @@ -0,0 +1,16 @@ +package com.xkcoding.springbootdemodubboconsumer; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class SpringBootDemoDubboConsumerApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/README.md b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/README.md new file mode 100644 index 0000000..0106a81 --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/README.md @@ -0,0 +1,106 @@ +# spring-boot-demo-dubbo-provider + +Spring Boot 与 Dubbo 整合服务的提供方 + +依赖 [spring-boot-demo-dubbo-api](../spring-boot-demo-dubbo-api/pom.xml) + +### pom.xml + +```xml + ++ * HelloServiceImpl + *
+ * + * @package: com.xkcoding.springbootdemodubboprovider.service.impl + * @description: HelloServiceImpl + * @author: yangkai.shen + * @date: Created in 2018/4/17 下午5:24 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Service +@Slf4j +public class HelloServiceImpl implements HelloService { + @Value("${server.port}") + private Integer port; + + @Override + public String hello(String name) { + log.info("Hello, {}, from port: {}",name, port); + return "Hello, " + name + ", from port: " + port; + } +} +``` + diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/pom.xml b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/pom.xml new file mode 100644 index 0000000..0ac60de --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/pom.xml @@ -0,0 +1,36 @@ + ++ * HelloServiceImpl + *
+ * + * @package: com.xkcoding.springbootdemodubboprovider.service.impl + * @description: HelloServiceImpl + * @author: yangkai.shen + * @date: Created in 2018/4/17 下午5:24 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Service +@Slf4j +public class HelloServiceImpl implements HelloService { + @Value("${server.port}") + private Integer port; + + @Override + public String hello(String name) { + log.info("Hello, {}, from port: {}",name, port); + return "Hello, " + name + ", from port: " + port; + } +} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/resources/application.yml b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/resources/application.yml new file mode 100644 index 0000000..350e696 --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/resources/application.yml @@ -0,0 +1,15 @@ +server: + port: 8082 +spring: + dubbo: + application: + name: dubbo-provider + base-package: com.xkcoding.springbootdemodubboprovider.service # dubbo服务发布者所在的包 + registry: + address: 127.0.0.1 # zookeeper注册中心的地址 + port: 2181 # zookeeper注册中心的端口 + protocol: + name: dubbo + serialization: hessian2 + provider: + retries: 0 \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/test/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplicationTests.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/test/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplicationTests.java new file mode 100644 index 0000000..298b474 --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/test/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplicationTests.java @@ -0,0 +1,16 @@ +package com.xkcoding.springbootdemodubboprovider; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class SpringBootDemoDubboProviderApplicationTests { + + @Test + public void contextLoads() { + } + +}