From 74746d7cdd7723b06ec43917baada758bcc4717f Mon Sep 17 00:00:00 2001 From: "Yangkai.Shen" <237497819@qq.com> Date: Tue, 17 Apr 2018 18:51:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20TODO.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.md | 2 +- spring-boot-demo-dubbo-parent/.gitignore | 25 +++ spring-boot-demo-dubbo-parent/README.md | 116 ++++++++++++ spring-boot-demo-dubbo-parent/pom.xml | 74 ++++++++ .../spring-boot-demo-dubbo-consumer/README.md | 165 ++++++++++++++++++ .../spring-boot-demo-dubbo-consumer/pom.xml | 35 ++++ ...pringBootDemoDubboConsumerApplication.java | 12 ++ .../controller/GreetController.java | 33 ++++ .../service/GreetService.java | 18 ++ .../service/impl/GreetServiceImpl.java | 30 ++++ .../src/main/resources/application.yml | 14 ++ ...BootDemoDubboConsumerApplicationTests.java | 16 ++ .../spring-boot-demo-dubbo-provider/README.md | 106 +++++++++++ .../spring-boot-demo-dubbo-provider/pom.xml | 36 ++++ ...pringBootDemoDubboProviderApplication.java | 12 ++ .../service/impl/HelloServiceImpl.java | 32 ++++ .../src/main/resources/application.yml | 15 ++ ...BootDemoDubboProviderApplicationTests.java | 16 ++ 18 files changed, 756 insertions(+), 1 deletion(-) create mode 100644 spring-boot-demo-dubbo-parent/.gitignore create mode 100644 spring-boot-demo-dubbo-parent/README.md create mode 100644 spring-boot-demo-dubbo-parent/pom.xml create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/README.md create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/pom.xml create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplication.java create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/controller/GreetController.java create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/GreetService.java create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/impl/GreetServiceImpl.java create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/resources/application.yml create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/test/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplicationTests.java create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/README.md create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/pom.xml create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplication.java create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/service/impl/HelloServiceImpl.java create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/resources/application.yml create mode 100644 spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/test/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplicationTests.java 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 + + + 4.0.0 + + com.xkcoding + spring-boot-demo-dubbo-parent + 0.0.1-SNAPSHOT + pom + + spring-boot-demo-dubbo-parent + Spring Boot 与 Dubbo 整合的父依赖 + + + org.springframework.boot + spring-boot-starter-parent + 2.0.1.RELEASE + + + + + spring-boot-demo-dubbo-api + spring-boot-demo-dubbo-provider + spring-boot-demo-dubbo-consumer + + + + UTF-8 + UTF-8 + 1.8 + 1.1.1 + + + + + org.springframework.boot + spring-boot-starter + + + + com.gitee.reger + spring-boot-starter-dubbo + ${spring-boot-starter-dubbo.version} + + + + org.projectlombok + lombok + 1.16.20 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.xkcoding + spring-boot-demo-dubbo-api + 0.0.1-SNAPSHOT + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + +``` + +### 步骤 + +1. 启动本地的 `Zookeeper` 服务,端口号为 **2181** + + > 这里 `Zookeeper` 可以直接使用单机版,如果需要配置集群版的,可以参考 http://xkcoding.com/2017/11/01/zookeeper-cluster.html + +2. 启动两个 `spring-boot-demo-dubbo-provider` 程序,端口号分别使用 **8082**、**8083** + +3. 启动 `spring-boot-demo-dubbo-consumer` 程序,端口号为 **9090** + +4. 浏览器输入 http://localhost:9090/greet?name=test + + 可以看到,**8082**和**8083**端口随机打印 + + > Hello, test, from port: 8082 + + 或 + + > Hello, test, from port: 8083 + +5. 本地启动 `dubbo-admin` 可以查看服务提供方和消费方,也可以配置负载均衡策略等等 + + > 关于 `dubbo-admin` 的安装和配置等,可以参考 http://xkcoding.com/2017/11/08/dubbo-admin-install.html \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/pom.xml b/spring-boot-demo-dubbo-parent/pom.xml new file mode 100644 index 0000000..4fbba8c --- /dev/null +++ b/spring-boot-demo-dubbo-parent/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.xkcoding + spring-boot-demo-dubbo-parent + 0.0.1-SNAPSHOT + pom + + spring-boot-demo-dubbo-parent + Spring Boot 与 Dubbo 整合的父依赖 + + + org.springframework.boot + spring-boot-starter-parent + 2.0.1.RELEASE + + + + + spring-boot-demo-dubbo-api + spring-boot-demo-dubbo-provider + spring-boot-demo-dubbo-consumer + + + + UTF-8 + UTF-8 + 1.8 + 1.1.1 + + + + + org.springframework.boot + spring-boot-starter + + + + com.gitee.reger + spring-boot-starter-dubbo + ${spring-boot-starter-dubbo.version} + + + + org.projectlombok + lombok + 1.16.20 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.xkcoding + spring-boot-demo-dubbo-api + 0.0.1-SNAPSHOT + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/README.md b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/README.md new file mode 100644 index 0000000..fa27a8e --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/README.md @@ -0,0 +1,165 @@ +# spring-boot-demo-dubbo-consumer + +Spring Boot 与 Dubbo 整合服务的消费方 + +依赖 [spring-boot-demo-dubbo-api](../spring-boot-demo-dubbo-api/pom.xml) + +### pom.xml + +```xml + + + 4.0.0 + + spring-boot-demo-dubbo-consumer + 0.0.1-SNAPSHOT + jar + + spring-boot-demo-dubbo-consumer + Spring Boot 与 Dubbo 整合服务的消费方 + + com.xkcoding + spring-boot-demo-dubbo-parent + 0.0.1-SNAPSHOT + ../pom.xml + + + + + org.springframework.boot + spring-boot-starter-web + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + +``` + +### application.yml + +```yaml +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 +``` + +### GreetController.java + +```java +package com.xkcoding.springbootdemodubboconsumer.controller; + +import com.xkcoding.springbootdemodubboconsumer.service.GreetService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 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 @@ + + + 4.0.0 + + spring-boot-demo-dubbo-consumer + 0.0.1-SNAPSHOT + jar + + spring-boot-demo-dubbo-consumer + Spring Boot 与 Dubbo 整合服务的消费方 + + com.xkcoding + spring-boot-demo-dubbo-parent + 0.0.1-SNAPSHOT + ../pom.xml + + + + + org.springframework.boot + spring-boot-starter-web + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplication.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplication.java new file mode 100644 index 0000000..08889a0 --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplication.java @@ -0,0 +1,12 @@ +package com.xkcoding.springbootdemodubboconsumer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootDemoDubboConsumerApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootDemoDubboConsumerApplication.class, args); + } +} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/controller/GreetController.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/controller/GreetController.java new file mode 100644 index 0000000..431e343 --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/controller/GreetController.java @@ -0,0 +1,33 @@ +package com.xkcoding.springbootdemodubboconsumer.controller; + +import com.xkcoding.springbootdemodubboconsumer.service.GreetService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 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 + + + 4.0.0 + + spring-boot-demo-dubbo-provider + 0.0.1-SNAPSHOT + jar + + spring-boot-demo-dubbo-provider + Spring Boot 与 Dubbo 整合服务的提供方 + + + com.xkcoding + spring-boot-demo-dubbo-parent + 0.0.1-SNAPSHOT + ../pom.xml + + + + + org.springframework.boot + spring-boot-starter-web + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + +``` + +### application.yml + +```yaml +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 +``` + +### HelloServiceImpl.java + +代码中的 `@Service` 使用的是 `Dubbo` 的注解,而不是 `Spring` 的注解 + +```java +package com.xkcoding.springbootdemodubboprovider.service.impl; + +import com.alibaba.dubbo.config.annotation.Service; +import com.xkcoding.springbootdemodubboapi.service.HelloService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; + +/** + *

+ * 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 @@ + + + 4.0.0 + + spring-boot-demo-dubbo-provider + 0.0.1-SNAPSHOT + jar + + spring-boot-demo-dubbo-provider + Spring Boot 与 Dubbo 整合服务的提供方 + + + com.xkcoding + spring-boot-demo-dubbo-parent + 0.0.1-SNAPSHOT + ../pom.xml + + + + + org.springframework.boot + spring-boot-starter-web + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplication.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplication.java new file mode 100644 index 0000000..2b5bfcd --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplication.java @@ -0,0 +1,12 @@ +package com.xkcoding.springbootdemodubboprovider; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootDemoDubboProviderApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootDemoDubboProviderApplication.class, args); + } +} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/service/impl/HelloServiceImpl.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/service/impl/HelloServiceImpl.java new file mode 100644 index 0000000..fe7e6da --- /dev/null +++ b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/service/impl/HelloServiceImpl.java @@ -0,0 +1,32 @@ +package com.xkcoding.springbootdemodubboprovider.service.impl; + +import com.alibaba.dubbo.config.annotation.Service; +import com.xkcoding.springbootdemodubboapi.service.HelloService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; + +/** + *

+ * 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() { + } + +}