From e99a9f522088d987b52f28cb42555044bf92f75a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=A9=AC=E5=93=A5?= Date: Tue, 8 Jan 2019 15:56:22 +0800 Subject: [PATCH] 0.1.x (#364) * Bug fix on test case * Polish apache/incubator-dubbo-spring-boot-project#327 & apache/incubator-dubbo-spring-boot-project#325 * Polish apache/incubator-dubbo-spring-boot-project#321 * Polish apache/incubator-dubbo-spring-boot-project#220 no program * Switch Yaml file * Update version to be 0.2.0 * Polish apache/incubator-dubbo-spring-boot-project#218 * Update Documents * Fix the test case's bugs * Fix plugins' issues * Fix test-cases * Fix test cases * Fixes an issue on DubboMvcEndpoint * Polish: Fix a relaxed property name issue * Optimize Awaiting implementation * Remove author from JavaDoc * Refactor * Merge * Update dependencies and implementations * Update Samples * Fix the test cases --- dubbo-spring-boot-autoconfigure/pom.xml | 3 +- ...ultPropertiesEnvironmentPostProcessor.java | 20 ++ ...AutoConfigurationOnMultipleConfigTest.java | 5 +- ...boAutoConfigurationOnSingleConfigTest.java | 4 +- ...ropertiesEnvironmentPostProcessorTest.java | 18 +- dubbo-spring-boot-parent/pom.xml | 69 ++--- .../consumer-sample/pom.xml | 74 +++++ ...bboAutoConfigurationConsumerBootstrap.java | 56 ++++ .../src/main/resources/application.yml | 3 + .../auto-configure-samples/pom.xml | 38 +++ .../provider-sample}/pom.xml | 25 +- ...boAutoConfigurationProviderBootstrap.java} | 11 +- .../provider/service/DefaultDemoService.java | 17 +- .../src/main/resources/application.properties | 12 + .../consumer-sample/pom.xml | 93 +++++++ .../DubboRegistryNacosConsumerBootstrap.java | 54 ++++ .../src/main/resources/application.yml | 11 + .../dubbo-registry-nacos-samples/pom.xml | 38 +++ .../provider-sample/pom.xml | 94 +++++++ .../DubboRegistryNacosProviderBootstrap.java | 38 +++ .../provider/service/DefaultDemoService.java} | 32 ++- .../src/main/resources/application.properties | 20 ++ .../consumer-sample}/pom.xml | 29 +- ...bboRegistryZooKeeperConsumerBootstrap.java | 54 ++++ .../src/main/resources/application.yml | 15 ++ .../dubbo-registry-zookeeper-samples/pom.xml | 38 +++ .../provider-sample/pom.xml | 88 ++++++ ...bboRegistryZooKeeperProviderBootstrap.java | 49 ++++ .../provider/bootstrap/EmbeddedZooKeeper.java | 252 ++++++++++++++++++ .../provider/service/DefaultDemoService.java | 42 +++ .../src/main/resources/application.properties | 22 ++ .../src/main/resources/application.yml | 31 --- .../resources/application-prod.properties | 9 - .../src/main/resources/application.properties | 25 -- .../consumer-sample/pom.xml | 74 +++++ ...nalizedConfigurationConsumerBootstrap.java | 54 ++++ .../src/main/resources/application.yml | 8 + .../pom.xml | 39 +++ .../provider-sample/pom.xml | 76 ++++++ ...alizedConfigurationProviderBootstrap.java} | 18 +- .../provider/service/DefaultDemoService.java | 42 +++ .../src/main/resources/application.properties | 19 ++ dubbo-spring-boot-samples/pom.xml | 10 +- .../pom.xml | 6 +- .../boot/dubbo/demo/consumer/DemoService.java | 0 45 files changed, 1535 insertions(+), 200 deletions(-) create mode 100644 dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/pom.xml create mode 100644 dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboAutoConfigurationConsumerBootstrap.java create mode 100644 dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/resources/application.yml create mode 100644 dubbo-spring-boot-samples/auto-configure-samples/pom.xml rename dubbo-spring-boot-samples/{dubbo-spring-boot-sample-consumer => auto-configure-samples/provider-sample}/pom.xml (78%) rename dubbo-spring-boot-samples/{dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboProviderDemo.java => auto-configure-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboAutoConfigurationProviderBootstrap.java} (80%) rename dubbo-spring-boot-samples/{dubbo-spring-boot-sample-provider => auto-configure-samples/provider-sample}/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java (77%) create mode 100644 dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/resources/application.properties create mode 100644 dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/pom.xml create mode 100644 dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboRegistryNacosConsumerBootstrap.java create mode 100644 dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/src/main/resources/application.yml create mode 100644 dubbo-spring-boot-samples/dubbo-registry-nacos-samples/pom.xml create mode 100644 dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/pom.xml create mode 100644 dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboRegistryNacosProviderBootstrap.java rename dubbo-spring-boot-samples/{dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/controller/DemoConsumerController.java => dubbo-registry-nacos-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java} (56%) create mode 100644 dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/resources/application.properties rename dubbo-spring-boot-samples/{dubbo-spring-boot-sample-provider => dubbo-registry-zookeeper-samples/consumer-sample}/pom.xml (80%) create mode 100644 dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboRegistryZooKeeperConsumerBootstrap.java create mode 100644 dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/src/main/resources/application.yml create mode 100644 dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/pom.xml create mode 100644 dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/pom.xml create mode 100644 dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboRegistryZooKeeperProviderBootstrap.java create mode 100644 dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/EmbeddedZooKeeper.java create mode 100644 dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java create mode 100644 dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/resources/application.properties delete mode 100644 dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.yml delete mode 100644 dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application-prod.properties delete mode 100644 dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application.properties create mode 100644 dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/pom.xml create mode 100644 dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboExternalizedConfigurationConsumerBootstrap.java create mode 100644 dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/resources/application.yml create mode 100644 dubbo-spring-boot-samples/externalized-configuration-samples/pom.xml create mode 100644 dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/pom.xml rename dubbo-spring-boot-samples/{dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboConsumerDemo.java => externalized-configuration-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboExternalizedConfigurationProviderBootstrap.java} (66%) create mode 100644 dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java create mode 100644 dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/resources/application.properties rename dubbo-spring-boot-samples/{dubbo-spring-boot-sample-api => sample-api}/pom.xml (92%) rename dubbo-spring-boot-samples/{dubbo-spring-boot-sample-api => sample-api}/src/main/java/com/alibaba/boot/dubbo/demo/consumer/DemoService.java (100%) diff --git a/dubbo-spring-boot-autoconfigure/pom.xml b/dubbo-spring-boot-autoconfigure/pom.xml index a878a658b..26097bb92 100644 --- a/dubbo-spring-boot-autoconfigure/pom.xml +++ b/dubbo-spring-boot-autoconfigure/pom.xml @@ -20,9 +20,8 @@ com.alibaba.boot dubbo-spring-boot-parent - 0.1.2-SNAPSHOT - ../dubbo-spring-boot-parent + ../dubbo-spring-boot-parent/pom.xml 4.0.0 diff --git a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessor.java b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessor.java index d8a671b95..3292bf9fa 100644 --- a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessor.java +++ b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessor.java @@ -64,6 +64,16 @@ public class DubboDefaultPropertiesEnvironmentPostProcessor implements Environme */ private static final String DUBBO_APPLICATION_NAME_PROPERTY = "dubbo.application.name"; + /** + * The property name of {@link EnableDubboConfig#multiple() @EnableDubboConfig.multiple()} + */ + private static final String DUBBO_CONFIG_MULTIPLE_PROPERTY = "dubbo.config.multiple"; + + /** + * The property name of {@link ApplicationConfig#getQosEnable() application's QOS enable} + */ + private static final String DUBBO_APPLICATION_QOS_ENABLE_PROPERTY = "dubbo.application.qos-enable"; + @Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { MutablePropertySources propertySources = environment.getPropertySources(); @@ -81,6 +91,8 @@ public int getOrder() { private Map createDefaultProperties(ConfigurableEnvironment environment) { Map defaultProperties = new HashMap(); setDubboApplicationNameProperty(environment, defaultProperties); + setDubboConfigMultipleProperty(defaultProperties); + setDubboApplicationQosEnableProperty(defaultProperties); return defaultProperties; } @@ -92,6 +104,14 @@ private void setDubboApplicationNameProperty(Environment environment, Map defaultProperties) { + defaultProperties.put(DUBBO_CONFIG_MULTIPLE_PROPERTY, Boolean.TRUE.toString()); + } + + private void setDubboApplicationQosEnableProperty(Map defaultProperties) { + defaultProperties.put(DUBBO_APPLICATION_QOS_ENABLE_PROPERTY, Boolean.FALSE.toString()); + } + /** * Copy from BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map) * diff --git a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnMultipleConfigTest.java b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnMultipleConfigTest.java index 8360d7fdb..fbcdabd8c 100644 --- a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnMultipleConfigTest.java +++ b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnMultipleConfigTest.java @@ -43,6 +43,7 @@ /** * {@link DubboAutoConfiguration} Test On multiple Dubbo Configuration * + * @author Mercy * @since 1.0.0 */ @RunWith(SpringJUnit4ClassRunner.class) @@ -152,7 +153,7 @@ public class DubboAutoConfigurationOnMultipleConfigTest { public void testMultipleDubboConfigBindingProperties() { - Assert.assertEquals(2, applications.size()); + Assert.assertEquals(3, applications.size()); Assert.assertEquals(1, modules.size()); @@ -176,7 +177,7 @@ public void testApplicationContext() { */ Map applications = beansOfTypeIncludingAncestors(applicationContext, ApplicationConfig.class); - Assert.assertEquals(2, applications.size()); + Assert.assertEquals(3, applications.size()); /** * Multiple {@link ModuleConfig} diff --git a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnSingleConfigTest.java b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnSingleConfigTest.java index 013adec9e..7f4cd5e16 100644 --- a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnSingleConfigTest.java +++ b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnSingleConfigTest.java @@ -150,7 +150,7 @@ public void testConsumerConfig() { @Test public void testMultipleDubboConfigConfiguration() { - Assert.assertNull(multipleDubboConfigConfiguration); + Assert.assertNotNull(multipleDubboConfigConfiguration); } @Test @@ -160,7 +160,7 @@ public void testSingleDubboConfigConfiguration() { @Test public void testServiceAnnotationBeanPostProcessor() { - Assert.assertNull(multipleDubboConfigConfiguration); + Assert.assertNotNull(multipleDubboConfigConfiguration); } } diff --git a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java index 626f2c9c6..d941a4f4c 100644 --- a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java +++ b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java @@ -51,7 +51,9 @@ public void testPostProcessEnvironment() { MutablePropertySources propertySources = environment.getPropertySources(); // Nothing to change PropertySource defaultPropertySource = propertySources.get("defaultProperties"); - Assert.assertNull(defaultPropertySource); + Assert.assertNotNull(defaultPropertySource); + Assert.assertEquals("true", defaultPropertySource.getProperty("dubbo.config.multiple")); + Assert.assertEquals("false", defaultPropertySource.getProperty("dubbo.application.qos-enable")); // Case 2 : Only set property "spring.application.name" environment.setProperty("spring.application.name", "demo-dubbo-application"); @@ -67,7 +69,7 @@ public void testPostProcessEnvironment() { environment.setProperty("dubbo.application.name", "demo-dubbo-application"); instance.postProcessEnvironment(environment, springApplication); defaultPropertySource = propertySources.get("defaultProperties"); - Assert.assertNull(defaultPropertySource); + Assert.assertNotNull(defaultPropertySource); dubboApplicationName = environment.getProperty("dubbo.application.name"); Assert.assertEquals("demo-dubbo-application", dubboApplicationName); @@ -81,5 +83,15 @@ public void testPostProcessEnvironment() { defaultPropertySource = propertySources.get("defaultProperties"); dubboApplicationName = defaultPropertySource.getProperty("dubbo.application.name"); Assert.assertEquals("demo-dubbo-application", dubboApplicationName); + + // Case 5 : Rest dubbo.config.multiple and dubbo.application.qos-enable + environment = new MockEnvironment(); + propertySources = environment.getPropertySources(); + propertySources.addLast(new MapPropertySource("defaultProperties", new HashMap())); + environment.setProperty("dubbo.config.multiple", "false"); + environment.setProperty("dubbo.application.qos-enable", "true"); + instance.postProcessEnvironment(environment, springApplication); + Assert.assertEquals("false", environment.getProperty("dubbo.config.multiple")); + Assert.assertEquals("true", environment.getProperty("dubbo.application.qos-enable")); } -} +} \ No newline at end of file diff --git a/dubbo-spring-boot-parent/pom.xml b/dubbo-spring-boot-parent/pom.xml index dae76a11f..5c08dc891 100644 --- a/dubbo-spring-boot-parent/pom.xml +++ b/dubbo-spring-boot-parent/pom.xml @@ -39,11 +39,8 @@ UTF-8 1.5.18.RELEASE 2.6.5 - 0.2 - 3.4.9 - 2.12.0 - 1.0.2 - + 0.0.2 + 0.6.2 -server -Xms256m -Xmx512m -XX:PermSize=64m -XX:MaxPermSize=128m -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true @@ -63,7 +60,6 @@ - org.springframework.boot @@ -73,6 +69,15 @@ import + + + com.alibaba + dubbo-dependencies-bom + ${dubbo.version} + pom + import + + com.alibaba @@ -94,54 +99,18 @@ - - - com.alibaba.spring - spring-context-support - ${alibaba-spring-context-support.version} - - - - - org.apache.zookeeper - zookeeper - ${zookeeper.version} - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - - + - com.101tec - zkclient - ${zkclient.version} - - - slf4j-api - org.slf4j - - - log4j - log4j - - - slf4j-log4j12 - org.slf4j - - + com.alibaba + dubbo-registry-nacos + ${dubbo-registry-nacos.version} + - org.apache.curator - curator-framework - ${curator-framework.version} + com.alibaba.nacos + nacos-client + ${nacos-client.version} diff --git a/dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/pom.xml b/dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/pom.xml new file mode 100644 index 000000000..27b9d9c09 --- /dev/null +++ b/dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/pom.xml @@ -0,0 +1,74 @@ + + + + com.alibaba.boot.samples + dubbo-spring-boot-auto-configure-samples + 0.1.2-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-spring-boot-auto-configure-consumer-sample + Dubbo Spring Boot Samples : Auto-Configure :: Consumer Sample + + + + + org.springframework.boot + spring-boot-starter + + + + com.alibaba.boot + dubbo-spring-boot-starter + ${project.version} + + + + com.alibaba + dubbo + + + + ${project.groupId} + dubbo-spring-boot-sample-api + ${project.version} + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboAutoConfigurationConsumerBootstrap.java b/dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboAutoConfigurationConsumerBootstrap.java new file mode 100644 index 000000000..ec85a2f98 --- /dev/null +++ b/dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboAutoConfigurationConsumerBootstrap.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.boot.dubbo.demo.consumer.bootstrap; + +import com.alibaba.boot.dubbo.demo.consumer.DemoService; +import com.alibaba.dubbo.config.annotation.Reference; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; + +/** + * Dubbo Auto Configuration Consumer Bootstrap + * + * @since 1.0.0 + */ +@EnableAutoConfiguration +public class DubboAutoConfigurationConsumerBootstrap { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @Reference(version = "1.0.0", url = "dubbo://localhost:12345") + private DemoService demoService; + + @Bean + public ApplicationRunner runner() { + return new ApplicationRunner() { + @Override + public void run(ApplicationArguments args) throws Exception { + logger.info(demoService.sayHello("mercyblitz")); + } + }; + } + + public static void main(String[] args) { + SpringApplication.run(DubboAutoConfigurationConsumerBootstrap.class).close(); + } +} diff --git a/dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/resources/application.yml b/dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/resources/application.yml new file mode 100644 index 000000000..cb7b13317 --- /dev/null +++ b/dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/resources/application.yml @@ -0,0 +1,3 @@ +spring: + application: + name: dubbo-auto-configure-consumer-sample \ No newline at end of file diff --git a/dubbo-spring-boot-samples/auto-configure-samples/pom.xml b/dubbo-spring-boot-samples/auto-configure-samples/pom.xml new file mode 100644 index 000000000..7e6b3c0e1 --- /dev/null +++ b/dubbo-spring-boot-samples/auto-configure-samples/pom.xml @@ -0,0 +1,38 @@ + + + + com.alibaba.boot.samples + dubbo-spring-boot-samples + 0.1.2-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-spring-boot-auto-configure-samples + Dubbo Spring Boot Samples : Auto-Configure + Dubbo Spring Boot Auto-Configure Samples + pom + + + consumer-sample + provider-sample + + + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/pom.xml b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/pom.xml similarity index 78% rename from dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/pom.xml rename to dubbo-spring-boot-samples/auto-configure-samples/provider-sample/pom.xml index 3637b7234..7f03257f8 100644 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/pom.xml +++ b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/pom.xml @@ -13,41 +13,35 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ---> - + - com.alibaba.boot - dubbo-spring-boot-samples + com.alibaba.boot.samples + dubbo-spring-boot-auto-configure-samples 0.1.2-SNAPSHOT ../pom.xml 4.0.0 - dubbo-spring-boot-sample-consumer - Dubbo Spring Boot Sample : Consumer + dubbo-spring-boot-auto-configure-provider-sample + Dubbo Spring Boot Samples : Auto-Configure :: Provider Sample org.springframework.boot - spring-boot-starter-web + spring-boot-starter - org.springframework.boot - spring-boot-actuator - - - - ${project.groupId} + com.alibaba.boot dubbo-spring-boot-starter ${project.version} - com.alibaba dubbo @@ -78,4 +72,5 @@ + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboProviderDemo.java b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboAutoConfigurationProviderBootstrap.java similarity index 80% rename from dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboProviderDemo.java rename to dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboAutoConfigurationProviderBootstrap.java index 18f6ba7b2..4fc972d93 100644 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboProviderDemo.java +++ b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboAutoConfigurationProviderBootstrap.java @@ -18,21 +18,20 @@ import com.alibaba.boot.dubbo.demo.provider.service.DefaultDemoService; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; /** - * Dubbo Provider Demo + * Dubbo Auto-Configuration Provider Bootstrap * * @see DefaultDemoService * @since 1.0.0 */ -@SpringBootApplication -public class DubboProviderDemo { +@EnableAutoConfiguration +public class DubboAutoConfigurationProviderBootstrap { public static void main(String[] args) { - new SpringApplicationBuilder(DubboProviderDemo.class) - .profiles("prod") + new SpringApplicationBuilder(DubboAutoConfigurationProviderBootstrap.class) .web(false) .run(args); } diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java similarity index 77% rename from dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java rename to dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java index 5a66ceabb..01dfccc3c 100644 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java +++ b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java @@ -19,21 +19,24 @@ import com.alibaba.boot.dubbo.demo.consumer.DemoService; import com.alibaba.dubbo.config.annotation.Service; +import org.springframework.beans.factory.annotation.Value; + /** * Default {@link DemoService} * * @see DemoService * @since 1.0.0 */ -@Service( - version = "${demo.service.version}", - protocol = "${dubbo.protocol.id}", - registry = "${dubbo.registry.id}" -) +@Service(version = "1.0.0") public class DefaultDemoService implements DemoService { + /** + * The default value of ${dubbo.application.name} is ${spring.application.name} + */ + @Value("${dubbo.application.name}") + private String serviceName; + public String sayHello(String name) { - return "Hello, " + name + " (from Spring Boot)"; + return String.format("[%s] : Hello, %s", serviceName, name); } - } \ No newline at end of file diff --git a/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/resources/application.properties b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/resources/application.properties new file mode 100644 index 000000000..85e8400e4 --- /dev/null +++ b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/resources/application.properties @@ -0,0 +1,12 @@ +# Spring boot application +spring.application.name=dubbo-auto-configuration-provider-demo +# Base packages to scan Dubbo Component: @com.alibaba.dubbo.config.annotation.Service +dubbo.scan.base-packages=com.alibaba.boot.dubbo.demo.provider.service +# Dubbo Application +## The default value of dubbo.application.name is ${spring.application.name} +## dubbo.application.name=${spring.application.name} +# Dubbo Protocol +dubbo.protocol.name=dubbo +dubbo.protocol.port=12345 +## Dubbo Registry +dubbo.registry.address=N/A \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/pom.xml b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/pom.xml new file mode 100644 index 000000000..9e75621f5 --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/pom.xml @@ -0,0 +1,93 @@ + + + + com.alibaba.boot.samples + dubbo-spring-boot-registry-nacos-samples + 0.1.2-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-spring-boot-registry-nacos-consumer-sample + Dubbo Spring Boot Samples : Registry Nacos :: Consumer Sample + + + + + org.springframework.boot + spring-boot-starter + + + + com.alibaba.boot + dubbo-spring-boot-starter + ${project.version} + + + + + com.alibaba + dubbo + + + + ${project.groupId} + dubbo-spring-boot-sample-api + ${project.version} + + + + + io.netty + netty-all + + + + + com.alibaba + dubbo-registry-nacos + + + + + com.alibaba.nacos + nacos-client + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboRegistryNacosConsumerBootstrap.java b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboRegistryNacosConsumerBootstrap.java new file mode 100644 index 000000000..6d8825548 --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboRegistryNacosConsumerBootstrap.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.boot.dubbo.demo.consumer.bootstrap; + +import com.alibaba.boot.dubbo.demo.consumer.DemoService; +import com.alibaba.dubbo.config.annotation.Reference; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; + +/** + * Dubbo Registry Nacos Consumer Bootstrap + */ +@EnableAutoConfiguration +public class DubboRegistryNacosConsumerBootstrap { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @Reference(version = "${demo.service.version}") + private DemoService demoService; + + @Bean + public ApplicationRunner runner() { + return new ApplicationRunner() { + @Override + public void run(ApplicationArguments args) throws Exception { + logger.info(demoService.sayHello("mercyblitz")); + } + }; + } + + public static void main(String[] args) { + SpringApplication.run(DubboRegistryNacosConsumerBootstrap.class).close(); + } +} diff --git a/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/src/main/resources/application.yml b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/src/main/resources/application.yml new file mode 100644 index 000000000..7889cf709 --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/src/main/resources/application.yml @@ -0,0 +1,11 @@ +spring: + application: + name: dubbo-registry-nacos-consumer-sample + +demo: + service: + version: 1.0.0 + +dubbo: + registry: + address: nacos://127.0.0.1:8848 \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/pom.xml b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/pom.xml new file mode 100644 index 000000000..100f64391 --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/pom.xml @@ -0,0 +1,38 @@ + + + + com.alibaba.boot.samples + dubbo-spring-boot-samples + 0.1.2-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-spring-boot-registry-nacos-samples + Dubbo Spring Boot Samples : Registry Nacos + Dubbo Spring Boot Registry Nacos Samples + pom + + + consumer-sample + provider-sample + + + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/pom.xml b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/pom.xml new file mode 100644 index 000000000..1d7c7fa0d --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/pom.xml @@ -0,0 +1,94 @@ + + + + com.alibaba.boot.samples + dubbo-spring-boot-registry-nacos-samples + 0.1.2-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-spring-boot-registry-nacos-provider-sample + Dubbo Spring Boot Samples : Registry Nacos :: Provider Sample + + + + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba.boot + dubbo-spring-boot-starter + ${project.version} + + + + + com.alibaba + dubbo + + + + ${project.groupId} + dubbo-spring-boot-sample-api + ${project.version} + + + + + io.netty + netty-all + + + + + com.alibaba + dubbo-registry-nacos + + + + + com.alibaba.nacos + nacos-client + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + repackage + + + + + + + + + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboRegistryNacosProviderBootstrap.java b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboRegistryNacosProviderBootstrap.java new file mode 100644 index 000000000..5fedfa722 --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboRegistryNacosProviderBootstrap.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.boot.dubbo.demo.provider.bootstrap; + +import com.alibaba.boot.dubbo.demo.provider.service.DefaultDemoService; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; + +/** + * Dubbo Registry ZooKeeper Provider Bootstrap + * + * @see DefaultDemoService + * @since 1.0.0 + */ +@EnableAutoConfiguration +public class DubboRegistryNacosProviderBootstrap { + + public static void main(String[] args) { + new SpringApplicationBuilder(DubboRegistryNacosProviderBootstrap.class) + .web(false) + .run(); + } +} diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/controller/DemoConsumerController.java b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java similarity index 56% rename from dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/controller/DemoConsumerController.java rename to dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java index a2be8191a..f1d9ae1c9 100644 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/controller/DemoConsumerController.java +++ b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java @@ -14,31 +14,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.boot.dubbo.demo.consumer.controller; +package com.alibaba.boot.dubbo.demo.provider.service; import com.alibaba.boot.dubbo.demo.consumer.DemoService; -import com.alibaba.dubbo.config.annotation.Reference; +import com.alibaba.dubbo.config.annotation.Service; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.beans.factory.annotation.Value; /** - * Demo Consumer Controller (REST) + * Default {@link DemoService} * - * @see RestController + * @see DemoService * @since 1.0.0 */ -@RestController -public class DemoConsumerController { +@Service(version = "${demo.service.version}") +public class DefaultDemoService implements DemoService { - @Reference(version = "${demo.service.version}", - url = "dubbo://localhost:12345") - private DemoService demoService; + /** + * The default value of ${dubbo.application.name} is ${spring.application.name} + */ + @Value("${dubbo.application.name}") + private String serviceName; - @RequestMapping("/sayHello") - public String sayHello(@RequestParam String name) { - return demoService.sayHello(name); + public String sayHello(String name) { + return String.format("[%s] : Hello, %s", serviceName, name); } - -} +} \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/resources/application.properties b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/resources/application.properties new file mode 100644 index 000000000..91635fb70 --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/resources/application.properties @@ -0,0 +1,20 @@ +# Spring boot application +spring.application.name=dubbo-registry-nacos-provider-sample + +# Base packages to scan Dubbo Component: @com.alibaba.dubbo.config.annotation.Service +dubbo.scan.base-packages=com.alibaba.boot.dubbo.demo.provider.service + +# Dubbo Application +## The default value of dubbo.application.name is ${spring.application.name} +## dubbo.application.name=${spring.application.name} + +# Dubbo Protocol +dubbo.protocol.name=dubbo +## Random port +dubbo.protocol.port=-1 + +## Dubbo Registry +dubbo.registry.address=nacos://127.0.0.1:8848 + +## DemoService version +demo.service.version=1.0.0 \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/pom.xml b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/pom.xml similarity index 80% rename from dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/pom.xml rename to dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/pom.xml index 97365d7ef..49d77ff78 100644 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/pom.xml +++ b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/pom.xml @@ -13,21 +13,20 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ---> - + - com.alibaba.boot - dubbo-spring-boot-samples + com.alibaba.boot.samples + dubbo-spring-boot-registry-zookeeper-samples 0.1.2-SNAPSHOT ../pom.xml 4.0.0 - dubbo-spring-boot-sample-provider - Dubbo Spring Boot Sample : Provider - + dubbo-spring-boot-registry-zookeeper-consumer-sample + Dubbo Spring Boot Samples : Registry Zookeeper :: Consumer Sample @@ -37,17 +36,11 @@ - org.springframework.boot - spring-boot-actuator - - - - ${project.groupId} + com.alibaba.boot dubbo-spring-boot-starter ${project.version} - com.alibaba dubbo @@ -59,6 +52,11 @@ ${project.version} + + org.apache.curator + curator-framework + + @@ -78,5 +76,4 @@ - \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboRegistryZooKeeperConsumerBootstrap.java b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboRegistryZooKeeperConsumerBootstrap.java new file mode 100644 index 000000000..c881b549c --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboRegistryZooKeeperConsumerBootstrap.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.boot.dubbo.demo.consumer.bootstrap; + +import com.alibaba.boot.dubbo.demo.consumer.DemoService; +import com.alibaba.dubbo.config.annotation.Reference; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; + +/** + * Dubbo Registry ZooKeeper Consumer Bootstrap + */ +@EnableAutoConfiguration +public class DubboRegistryZooKeeperConsumerBootstrap { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @Reference(version = "${demo.service.version}") + private DemoService demoService; + + @Bean + public ApplicationRunner runner() { + return new ApplicationRunner() { + @Override + public void run(ApplicationArguments args) throws Exception { + logger.info(demoService.sayHello("mercyblitz")); + } + }; + } + + public static void main(String[] args) { + SpringApplication.run(DubboRegistryZooKeeperConsumerBootstrap.class).close(); + } +} diff --git a/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/src/main/resources/application.yml b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/src/main/resources/application.yml new file mode 100644 index 000000000..88846fbed --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/src/main/resources/application.yml @@ -0,0 +1,15 @@ +spring: + application: + name: dubbo-registry-zookeeper-consumer-sample + +demo: + service: + version: 1.0.0 + +embedded: + zookeeper: + port: 2181 + +dubbo: + registry: + address: zookeeper://127.0.0.1:${embedded.zookeeper.port} \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/pom.xml b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/pom.xml new file mode 100644 index 000000000..434a5ff51 --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/pom.xml @@ -0,0 +1,38 @@ + + + + com.alibaba.boot.samples + dubbo-spring-boot-samples + 0.1.2-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-spring-boot-registry-zookeeper-samples + Dubbo Spring Boot Samples : Registry Zookeeper + Dubbo Spring Boot Registry Zookeeper Samples + pom + + + consumer-sample + provider-sample + + + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/pom.xml b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/pom.xml new file mode 100644 index 000000000..fdcb98fa5 --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/pom.xml @@ -0,0 +1,88 @@ + + + + com.alibaba.boot.samples + dubbo-spring-boot-registry-zookeeper-samples + 0.1.2-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-spring-boot-registry-zookeeper-provider-sample + Dubbo Spring Boot Samples : Registry Zookeeper :: Provider Sample + + + + + + org.springframework.boot + spring-boot-starter + + + + com.alibaba.boot + dubbo-spring-boot-starter + ${project.version} + + + + + com.alibaba + dubbo + + + + ${project.groupId} + dubbo-spring-boot-sample-api + ${project.version} + + + + + org.apache.zookeeper + zookeeper + + + + org.apache.curator + curator-framework + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + repackage + + + + + + + + + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboRegistryZooKeeperProviderBootstrap.java b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboRegistryZooKeeperProviderBootstrap.java new file mode 100644 index 000000000..4290af318 --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboRegistryZooKeeperProviderBootstrap.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.boot.dubbo.demo.provider.bootstrap; + +import com.alibaba.boot.dubbo.demo.provider.service.DefaultDemoService; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.core.env.Environment; + +/** + * Dubbo Registry ZooKeeper Provider Bootstrap + * + * @see DefaultDemoService + * @since 1.0.0 + */ +@EnableAutoConfiguration +public class DubboRegistryZooKeeperProviderBootstrap { + + public static void main(String[] args) { + new SpringApplicationBuilder(DubboRegistryZooKeeperProviderBootstrap.class) + .web(false) + .listeners(new ApplicationListener() { + @Override + public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { + Environment environment = event.getEnvironment(); + int port = environment.getProperty("embedded.zookeeper.port", int.class); + new EmbeddedZooKeeper(port, false).start(); + } + }). + run(args); + } +} diff --git a/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/EmbeddedZooKeeper.java b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/EmbeddedZooKeeper.java new file mode 100644 index 000000000..ced63442b --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/EmbeddedZooKeeper.java @@ -0,0 +1,252 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.boot.dubbo.demo.provider.bootstrap; + + +import org.apache.zookeeper.server.ServerConfig; +import org.apache.zookeeper.server.ZooKeeperServerMain; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.SmartLifecycle; +import org.springframework.util.ErrorHandler; +import org.springframework.util.SocketUtils; + +import java.io.File; +import java.lang.reflect.Method; +import java.util.Properties; +import java.util.UUID; + +/** + * from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java + *

+ * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper. + *

+ * NOTE: at least an external standalone server (if not an ensemble) are recommended, even for + * org.springframework.xd.dirt.server.singlenode.SingleNodeApplication + * + * @author Patrick Peralta + * @author Mark Fisher + * @author David Turanski + */ +public class EmbeddedZooKeeper implements SmartLifecycle { + + /** + * Logger. + */ + private static final Logger logger = LoggerFactory.getLogger(EmbeddedZooKeeper.class); + + /** + * ZooKeeper client port. This will be determined dynamically upon startup. + */ + private final int clientPort; + + /** + * Whether to auto-start. Default is true. + */ + private boolean autoStartup = true; + + /** + * Lifecycle phase. Default is 0. + */ + private int phase = 0; + + /** + * Thread for running the ZooKeeper server. + */ + private volatile Thread zkServerThread; + + /** + * ZooKeeper server. + */ + private volatile ZooKeeperServerMain zkServer; + + /** + * {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. + */ + private ErrorHandler errorHandler; + + private boolean daemon = true; + + /** + * Construct an EmbeddedZooKeeper with a random port. + */ + public EmbeddedZooKeeper() { + clientPort = SocketUtils.findAvailableTcpPort(); + } + + /** + * Construct an EmbeddedZooKeeper with the provided port. + * + * @param clientPort port for ZooKeeper server to bind to + */ + public EmbeddedZooKeeper(int clientPort, boolean daemon) { + this.clientPort = clientPort; + this.daemon = daemon; + } + + /** + * Returns the port that clients should use to connect to this embedded server. + * + * @return dynamically determined client port + */ + public int getClientPort() { + return this.clientPort; + } + + /** + * Specify whether to start automatically. Default is true. + * + * @param autoStartup whether to start automatically + */ + public void setAutoStartup(boolean autoStartup) { + this.autoStartup = autoStartup; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isAutoStartup() { + return this.autoStartup; + } + + /** + * Specify the lifecycle phase for the embedded server. + * + * @param phase the lifecycle phase + */ + public void setPhase(int phase) { + this.phase = phase; + } + + /** + * {@inheritDoc} + */ + @Override + public int getPhase() { + return this.phase; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isRunning() { + return (zkServerThread != null); + } + + /** + * Start the ZooKeeper server in a background thread. + *

+ * Register an error handler via {@link #setErrorHandler} in order to handle + * any exceptions thrown during startup or execution. + */ + @Override + public synchronized void start() { + if (zkServerThread == null) { + zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper Server Starter"); + zkServerThread.setDaemon(daemon); + zkServerThread.start(); + } + } + + /** + * Shutdown the ZooKeeper server. + */ + @Override + public synchronized void stop() { + if (zkServerThread != null) { + // The shutdown method is protected...thus this hack to invoke it. + // This will log an exception on shutdown; see + // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for details. + try { + Method shutdown = ZooKeeperServerMain.class.getDeclaredMethod("shutdown"); + shutdown.setAccessible(true); + shutdown.invoke(zkServer); + } catch (Exception e) { + throw new RuntimeException(e); + } + + // It is expected that the thread will exit after + // the server is shutdown; this will block until + // the shutdown is complete. + try { + zkServerThread.join(5000); + zkServerThread = null; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + logger.warn("Interrupted while waiting for embedded ZooKeeper to exit"); + // abandoning zk thread + zkServerThread = null; + } + } + } + + /** + * Stop the server if running and invoke the callback when complete. + */ + @Override + public void stop(Runnable callback) { + stop(); + callback.run(); + } + + /** + * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. If none + * is provided, only error-level logging will occur. + * + * @param errorHandler the {@link ErrorHandler} to be invoked + */ + public void setErrorHandler(ErrorHandler errorHandler) { + this.errorHandler = errorHandler; + } + + /** + * Runnable implementation that starts the ZooKeeper server. + */ + private class ServerRunnable implements Runnable { + + @Override + public void run() { + try { + Properties properties = new Properties(); + File file = new File(System.getProperty("java.io.tmpdir") + + File.separator + UUID.randomUUID()); + file.deleteOnExit(); + properties.setProperty("dataDir", file.getAbsolutePath()); + properties.setProperty("clientPort", String.valueOf(clientPort)); + + QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); + quorumPeerConfig.parseProperties(properties); + + zkServer = new ZooKeeperServerMain(); + ServerConfig configuration = new ServerConfig(); + configuration.readFrom(quorumPeerConfig); + + zkServer.runFromConfig(configuration); + } catch (Exception e) { + if (errorHandler != null) { + errorHandler.handleError(e); + } else { + logger.error("Exception running embedded ZooKeeper", e); + } + } + } + } + +} diff --git a/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java new file mode 100644 index 000000000..f1d9ae1c9 --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.boot.dubbo.demo.provider.service; + +import com.alibaba.boot.dubbo.demo.consumer.DemoService; +import com.alibaba.dubbo.config.annotation.Service; + +import org.springframework.beans.factory.annotation.Value; + +/** + * Default {@link DemoService} + * + * @see DemoService + * @since 1.0.0 + */ +@Service(version = "${demo.service.version}") +public class DefaultDemoService implements DemoService { + + /** + * The default value of ${dubbo.application.name} is ${spring.application.name} + */ + @Value("${dubbo.application.name}") + private String serviceName; + + public String sayHello(String name) { + return String.format("[%s] : Hello, %s", serviceName, name); + } +} \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/resources/application.properties b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/resources/application.properties new file mode 100644 index 000000000..30aa324ed --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/resources/application.properties @@ -0,0 +1,22 @@ +# Spring boot application +spring.application.name=dubbo-registry-zookeeper-provider-sample + +# Base packages to scan Dubbo Component: @com.alibaba.dubbo.config.annotation.Service +dubbo.scan.base-packages=com.alibaba.boot.dubbo.demo.provider.service + +# Dubbo Application +## The default value of dubbo.application.name is ${spring.application.name} +## dubbo.application.name=${spring.application.name} + +embedded.zookeeper.port = 2181 + +# Dubbo Protocol +dubbo.protocol.name=dubbo +## Random port +dubbo.protocol.port=-1 + +## Dubbo Registry +dubbo.registry.address=zookeeper://127.0.0.1:${embedded.zookeeper.port} + +## DemoService version +demo.service.version=1.0.0 \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.yml b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.yml deleted file mode 100644 index b61aec0e4..000000000 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.yml +++ /dev/null @@ -1,31 +0,0 @@ -spring: - application: - name: dubbo-consumer-demo - -server: - port: 8080 - -management: - port: 8081 - security: - enabled: false - -dubbo: - protocol: - id: dubbo - name: dubbo - port: 12345 - ---- -spring: - profiles: prod - -endpoints: - dubbo: - enabled: false - -management: - health: - dubbo: - status: - defaults: memory \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application-prod.properties b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application-prod.properties deleted file mode 100644 index 421a14005..000000000 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application-prod.properties +++ /dev/null @@ -1,9 +0,0 @@ -# Application properties on prod profile -# Dubbo Endpoint (default status is disable) -endpoints.dubbo.enabled = true - -# Dubbo Health -## StatusChecker Name defaults (default : "memory", "load" ) -management.health.dubbo.status.defaults = memory -## StatusChecker Name extras (default : empty ) -management.health.dubbo.status.extras = load,threadpool \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application.properties b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application.properties deleted file mode 100644 index d0d1f2c91..000000000 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application.properties +++ /dev/null @@ -1,25 +0,0 @@ -# Spring boot application -spring.application.name = dubbo-provider-demo -server.port = 9090 -management.security.enabled = false - -# Service Version -demo.service.version = 1.0.0 - -# Base packages to scan Dubbo Components (e.g @Service , @Reference) -dubbo.scan.basePackages = com.alibaba.boot.dubbo.demo.provider.service - -# Dubbo Config properties -## ApplicationConfig Bean -dubbo.application.qos.port=22222 -dubbo.application.qos.enable=true - -## ProtocolConfig Bean -dubbo.protocol.id = dubbo -dubbo.protocol.name = dubbo -dubbo.protocol.port = 12345 -dubbo.protocol.status = server - -## RegistryConfig Bean -dubbo.registry.id = my-registry -dubbo.registry.address = N/A \ No newline at end of file diff --git a/dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/pom.xml b/dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/pom.xml new file mode 100644 index 000000000..d88491054 --- /dev/null +++ b/dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/pom.xml @@ -0,0 +1,74 @@ + + + + com.alibaba.boot.samples + dubbo-spring-boot-externalized-configuration-samples + 0.1.2-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-spring-boot-externalized-configuration-consumer-sample + Dubbo Spring Boot Samples : Externalized Configuration :: Consumer Sample + + + + + org.springframework.boot + spring-boot-starter + + + + com.alibaba.boot + dubbo-spring-boot-starter + ${project.version} + + + + com.alibaba + dubbo + + + + ${project.groupId} + dubbo-spring-boot-sample-api + ${project.version} + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboExternalizedConfigurationConsumerBootstrap.java b/dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboExternalizedConfigurationConsumerBootstrap.java new file mode 100644 index 000000000..6819e2e18 --- /dev/null +++ b/dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboExternalizedConfigurationConsumerBootstrap.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.boot.dubbo.demo.consumer.bootstrap; + +import com.alibaba.boot.dubbo.demo.consumer.DemoService; +import com.alibaba.dubbo.config.annotation.Reference; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; + +/** + * Dubbo Externalized Configuration Consumer Bootstrap + */ +@EnableAutoConfiguration +public class DubboExternalizedConfigurationConsumerBootstrap { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @Reference(version = "${demo.service.version}", url = "${demo.service.url}") + private DemoService demoService; + + @Bean + public ApplicationRunner runner() { + return new ApplicationRunner() { + @Override + public void run(ApplicationArguments args) throws Exception { + logger.info(demoService.sayHello("mercyblitz")); + } + }; + } + + public static void main(String[] args) { + SpringApplication.run(DubboExternalizedConfigurationConsumerBootstrap.class).close(); + } +} diff --git a/dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/resources/application.yml b/dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/resources/application.yml new file mode 100644 index 000000000..e3aef4286 --- /dev/null +++ b/dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/resources/application.yml @@ -0,0 +1,8 @@ +spring: + application: + name: dubbo-externalized-configuration-consumer-sample + +demo: + service: + version: 1.0.0 + url: dubbo://localhost:12345 \ No newline at end of file diff --git a/dubbo-spring-boot-samples/externalized-configuration-samples/pom.xml b/dubbo-spring-boot-samples/externalized-configuration-samples/pom.xml new file mode 100644 index 000000000..89d3b2db9 --- /dev/null +++ b/dubbo-spring-boot-samples/externalized-configuration-samples/pom.xml @@ -0,0 +1,39 @@ + + + + com.alibaba.boot.samples + dubbo-spring-boot-samples + 0.1.2-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-spring-boot-externalized-configuration-samples + Dubbo Spring Boot Samples : Externalized Configuration + Dubbo Spring Boot Externalized Configuration Samples + pom + + + consumer-sample + provider-sample + + + + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/pom.xml b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/pom.xml new file mode 100644 index 000000000..8261c052a --- /dev/null +++ b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/pom.xml @@ -0,0 +1,76 @@ + + + + com.alibaba.boot.samples + dubbo-spring-boot-externalized-configuration-samples + 0.1.2-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-spring-boot-externalized-configuration-provider-sample + Dubbo Spring Boot Samples : Externalized Configuration :: Provider Sample + + + + + + org.springframework.boot + spring-boot-starter + + + + com.alibaba.boot + dubbo-spring-boot-starter + ${project.version} + + + + com.alibaba + dubbo + + + + ${project.groupId} + dubbo-spring-boot-sample-api + ${project.version} + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + repackage + + + + + + + + + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboConsumerDemo.java b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboExternalizedConfigurationProviderBootstrap.java similarity index 66% rename from dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboConsumerDemo.java rename to dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboExternalizedConfigurationProviderBootstrap.java index 12fb7b7b8..a47c4c1e9 100644 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboConsumerDemo.java +++ b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboExternalizedConfigurationProviderBootstrap.java @@ -14,25 +14,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.boot.dubbo.demo.consumer.bootstrap; +package com.alibaba.boot.dubbo.demo.provider.bootstrap; -import com.alibaba.boot.dubbo.demo.consumer.controller.DemoConsumerController; +import com.alibaba.boot.dubbo.demo.provider.service.DefaultDemoService; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; /** - * Dubbo Consumer Demo + * Dubbo Externalized Configuration Provider Bootstrap * - * @see DemoConsumerController + * @see DefaultDemoService * @since 1.0.0 */ -@SpringBootApplication(scanBasePackages = "com.alibaba.boot.dubbo.demo.consumer.controller") -public class DubboConsumerDemo { +@EnableAutoConfiguration +public class DubboExternalizedConfigurationProviderBootstrap { public static void main(String[] args) { - new SpringApplicationBuilder(DubboConsumerDemo.class) - .profiles("prod") + new SpringApplicationBuilder(DubboExternalizedConfigurationProviderBootstrap.class) + .web(false) .run(args); } } diff --git a/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java new file mode 100644 index 000000000..f1d9ae1c9 --- /dev/null +++ b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.boot.dubbo.demo.provider.service; + +import com.alibaba.boot.dubbo.demo.consumer.DemoService; +import com.alibaba.dubbo.config.annotation.Service; + +import org.springframework.beans.factory.annotation.Value; + +/** + * Default {@link DemoService} + * + * @see DemoService + * @since 1.0.0 + */ +@Service(version = "${demo.service.version}") +public class DefaultDemoService implements DemoService { + + /** + * The default value of ${dubbo.application.name} is ${spring.application.name} + */ + @Value("${dubbo.application.name}") + private String serviceName; + + public String sayHello(String name) { + return String.format("[%s] : Hello, %s", serviceName, name); + } +} \ No newline at end of file diff --git a/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/resources/application.properties b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/resources/application.properties new file mode 100644 index 000000000..398e99689 --- /dev/null +++ b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/resources/application.properties @@ -0,0 +1,19 @@ +# Spring boot application +spring.application.name=dubbo-externalized-configuration-provider-sample + +# Base packages to scan Dubbo Component: @com.alibaba.dubbo.config.annotation.Service +dubbo.scan.base-packages=com.alibaba.boot.dubbo.demo.provider.service + +# Dubbo Application +## The default value of dubbo.application.name is ${spring.application.name} +## dubbo.application.name=${spring.application.name} + +# Dubbo Protocol +dubbo.protocol.name=dubbo +dubbo.protocol.port=12345 + +## Dubbo Registry +dubbo.registry.address=N/A + +## DemoService version +demo.service.version=1.0.0 \ No newline at end of file diff --git a/dubbo-spring-boot-samples/pom.xml b/dubbo-spring-boot-samples/pom.xml index 28aab4495..1d4d54999 100644 --- a/dubbo-spring-boot-samples/pom.xml +++ b/dubbo-spring-boot-samples/pom.xml @@ -25,14 +25,18 @@ 4.0.0 + com.alibaba.boot.samples dubbo-spring-boot-samples pom Dubbo Spring Boot Samples Dubbo Spring Boot Samples + - dubbo-spring-boot-sample-provider - dubbo-spring-boot-sample-consumer - dubbo-spring-boot-sample-api + sample-api + auto-configure-samples + externalized-configuration-samples + dubbo-registry-nacos-samples + dubbo-registry-zookeeper-samples diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-api/pom.xml b/dubbo-spring-boot-samples/sample-api/pom.xml similarity index 92% rename from dubbo-spring-boot-samples/dubbo-spring-boot-sample-api/pom.xml rename to dubbo-spring-boot-samples/sample-api/pom.xml index baf5da24d..1278e6899 100644 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-api/pom.xml +++ b/dubbo-spring-boot-samples/sample-api/pom.xml @@ -13,12 +13,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ---> + --> - com.alibaba.boot + com.alibaba.boot.samples dubbo-spring-boot-samples 0.1.2-SNAPSHOT ../pom.xml @@ -26,6 +26,6 @@ 4.0.0 dubbo-spring-boot-sample-api - Dubbo Spring Boot Sample : API + Dubbo Spring Boot Samples : API \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-api/src/main/java/com/alibaba/boot/dubbo/demo/consumer/DemoService.java b/dubbo-spring-boot-samples/sample-api/src/main/java/com/alibaba/boot/dubbo/demo/consumer/DemoService.java similarity index 100% rename from dubbo-spring-boot-samples/dubbo-spring-boot-sample-api/src/main/java/com/alibaba/boot/dubbo/demo/consumer/DemoService.java rename to dubbo-spring-boot-samples/sample-api/src/main/java/com/alibaba/boot/dubbo/demo/consumer/DemoService.java