From c267f25f896eb683825da941b1f8b09ad3b94bab Mon Sep 17 00:00:00 2001 From: javahongxi Date: Mon, 3 Dec 2018 22:33:45 +0800 Subject: [PATCH] DubboConfig optimise --- .../dubbo/demo/consumer/config/DubboConfig.java | 11 +++++------ .../whatsmars/dubbo/demo/consumer/rpc/DemoRpc.java | 2 +- .../src/main/resources/application.yml | 5 +++-- .../dubbo/demo/provider/config/DubboConfig.java | 11 +++++------ .../dubbo/demo/provider/service/OtherServiceImpl.java | 2 +- .../src/main/resources/application.yml | 5 +++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/config/DubboConfig.java b/whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/config/DubboConfig.java index fccbb99d..7bb4f16a 100644 --- a/whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/config/DubboConfig.java +++ b/whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/config/DubboConfig.java @@ -13,14 +13,13 @@ public class DubboConfig { /** * 配置文件里配置默认的,这里配置其他需要的 - * @param otherZK - * @return */ - @Bean("otherZK") - public RegistryConfig registryConfig(@Value("${registry.zk.other}") String otherZK) { + @Bean("otherRegistry") + public RegistryConfig otherRegistry(@Value("${registry.other.address}") String address, + @Value("${registry.other.id}") String id) { RegistryConfig registry = new RegistryConfig(); - registry.setId("otherZK"); - registry.setAddress(otherZK); + registry.setAddress(address); + registry.setId(id); return registry; } } diff --git a/whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/rpc/DemoRpc.java b/whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/rpc/DemoRpc.java index b070e109..ddcf1f4c 100644 --- a/whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/rpc/DemoRpc.java +++ b/whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/rpc/DemoRpc.java @@ -15,7 +15,7 @@ public class DemoRpc { @Reference(version = "1.0.0") private DemoService demoService; - @Reference(version = "1.0.0", registry = "otherZK") + @Reference(version = "1.0.0", registry = "otherRegistry") private OtherService otherService; public String sayHello(String name) { diff --git a/whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/resources/application.yml b/whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/resources/application.yml index 2e178298..de6c8720 100644 --- a/whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/resources/application.yml +++ b/whatsmars-dubbo/whatsmars-dubbo-consumer-boot/src/main/resources/application.yml @@ -17,5 +17,6 @@ dubbo: qosPort: 22224 registry: - zk: - other: zookeeper://127.0.0.1:2181 + other: + address: zookeeper://127.0.0.1:2181 + id: other diff --git a/whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/config/DubboConfig.java b/whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/config/DubboConfig.java index 0448181a..360cc808 100644 --- a/whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/config/DubboConfig.java +++ b/whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/config/DubboConfig.java @@ -13,14 +13,13 @@ public class DubboConfig { /** * 配置文件里配置默认的,这里配置其他需要的 - * @param otherZK - * @return */ - @Bean("otherZK") - public RegistryConfig registryConfig(@Value("${registry.zk.other}") String otherZK) { + @Bean("otherRegistry") + public RegistryConfig otherRegistry(@Value("${registry.other.address}") String address, + @Value("${registry.other.id}") String id) { RegistryConfig registry = new RegistryConfig(); - registry.setId("otherZK"); - registry.setAddress(otherZK); + registry.setAddress(address); + registry.setId(id); return registry; } } diff --git a/whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/service/OtherServiceImpl.java b/whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/service/OtherServiceImpl.java index b1257326..0cbb8464 100644 --- a/whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/service/OtherServiceImpl.java +++ b/whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/service/OtherServiceImpl.java @@ -16,7 +16,7 @@ import java.util.Date; version = "1.0.0", application = "${dubbo.application.id}", protocol = "${dubbo.protocol.id}", - registry = "otherZK" + registry = "otherRegistry" ) public class OtherServiceImpl implements OtherService { diff --git a/whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/resources/application.yml b/whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/resources/application.yml index d26fb411..1619d725 100644 --- a/whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/resources/application.yml +++ b/whatsmars-dubbo/whatsmars-dubbo-provider-boot/src/main/resources/application.yml @@ -28,5 +28,6 @@ management: enabled: false registry: - zk: - other: zookeeper://127.0.0.1:2181 + other: + address: zookeeper://127.0.0.1:2181 + id: other -- GitLab