This is an automated email from the ASF dual-hosted git repository.
mercyblitz pushed a commit to branch 0.2.1-release
in repository
https://gitbox.apache.org/repos/asf/incubator-dubbo-spring-boot-project.git
The following commit(s) were added to refs/heads/0.2.1-release by this push:
new d56dac0 0.2.1 (#362)
new ef626c8 Merge branch 'master' into 0.2.1-release
d56dac0 is described below
commit d56dac07981ce7c75a4afab9639e05ef05e9489e
Author: 小马哥 <[email protected]>
AuthorDate: Tue Jan 8 13:48:48 2019 +0800
0.2.1 (#362)
* 0.2.1 (#345)
* Fix apache/incubator-dubbo-spring-boot-project#169
* Polish : apache/incubator-dubbo-spring-boot-project#324 &
apache/incubator-dubbo-spring-boot-project#325
* Polish : apache/incubator-dubbo-spring-boot-project#315
* Polish : apache/incubator-dubbo-spring-boot-project#321
* Polish : apache/incubator-dubbo-spring-boot-project#321
* Polish : apache/incubator-dubbo-spring-boot-project#321 for test case
* Polish : Update Demos
* Polish : Update version to be 0.2.1
* Polish : apache/incubator-dubbo-spring-boot-project#319
* Polish : apache/incubator-dubbo-spring-boot-project#226
* Polish : apache/incubator-dubbo-spring-boot-project#309
* Fix the test case's bugs
* Fix the test case's bugs
* Fix a JavaDoc issue
* Update SNAPSHOT and add exclude list
* Update SNAPSHOT to be 0.2.1-SNAPSHOT
* Update JDK versions
* Update JDK versions
* Reactor & remove author info
* Refactor : to save a shutdown hook thread
* 0.2.1 (#346)
* Fix apache/incubator-dubbo-spring-boot-project#169
* Polish : apache/incubator-dubbo-spring-boot-project#324 &
apache/incubator-dubbo-spring-boot-project#325
* Polish : apache/incubator-dubbo-spring-boot-project#315
* Polish : apache/incubator-dubbo-spring-boot-project#321
* Polish : apache/incubator-dubbo-spring-boot-project#321
* Polish : apache/incubator-dubbo-spring-boot-project#321 for test case
* Polish : Update Demos
* Polish : Update version to be 0.2.1
* Polish : apache/incubator-dubbo-spring-boot-project#319
* Polish : apache/incubator-dubbo-spring-boot-project#226
* Polish : apache/incubator-dubbo-spring-boot-project#309
* Fix the test case's bugs
* Fix the test case's bugs
* Fix a JavaDoc issue
* Update SNAPSHOT and add exclude list
* Update SNAPSHOT to be 0.2.1-SNAPSHOT
* Update JDK versions
* Update JDK versions
* Reactor & remove author info
* Refactor : to save a shutdown hook thread
* Remove javax.servlet:javax.servlet-api:3.1.0 that may cause class
conflict, and use indirectly dependencies from spring-boot-starter-*
* Polish apache/incubator-dubbo-spring-boot-project#341
* 0.2.1 (#357)
* Fix apache/incubator-dubbo-spring-boot-project#169
* Polish : apache/incubator-dubbo-spring-boot-project#324 &
apache/incubator-dubbo-spring-boot-project#325
* Polish : apache/incubator-dubbo-spring-boot-project#315
* Polish : apache/incubator-dubbo-spring-boot-project#321
* Polish : apache/incubator-dubbo-spring-boot-project#321
* Polish : apache/incubator-dubbo-spring-boot-project#321 for test case
* Polish : Update Demos
* Polish : Update version to be 0.2.1
* Polish : apache/incubator-dubbo-spring-boot-project#319
* Polish : apache/incubator-dubbo-spring-boot-project#226
* Polish : apache/incubator-dubbo-spring-boot-project#309
* Fix the test case's bugs
* Fix the test case's bugs
* Fix a JavaDoc issue
* Update SNAPSHOT and add exclude list
* Update SNAPSHOT to be 0.2.1-SNAPSHOT
* Update JDK versions
* Update JDK versions
* Reactor & remove author info
* Refactor : to save a shutdown hook thread
* Remove javax.servlet:javax.servlet-api:3.1.0 that may cause class
conflict, and use indirectly dependencies from spring-boot-starter-*
* Polish apache/incubator-dubbo-spring-boot-project#341
* Add the samples
* Add a license
* 0.2.1 (#360)
* Fix apache/incubator-dubbo-spring-boot-project#169
* Polish : apache/incubator-dubbo-spring-boot-project#324 &
apache/incubator-dubbo-spring-boot-project#325
* Polish : apache/incubator-dubbo-spring-boot-project#315
* Polish : apache/incubator-dubbo-spring-boot-project#321
* Polish : apache/incubator-dubbo-spring-boot-project#321
* Polish : apache/incubator-dubbo-spring-boot-project#321 for test case
* Polish : Update Demos
* Polish : Update version to be 0.2.1
* Polish : apache/incubator-dubbo-spring-boot-project#319
* Polish : apache/incubator-dubbo-spring-boot-project#226
* Polish : apache/incubator-dubbo-spring-boot-project#309
* Fix the test case's bugs
* Fix the test case's bugs
* Fix a JavaDoc issue
* Update SNAPSHOT and add exclude list
* Update SNAPSHOT to be 0.2.1-SNAPSHOT
* Update JDK versions
* Update JDK versions
* Reactor & remove author info
* Refactor : to save a shutdown hook thread
* Remove javax.servlet:javax.servlet-api:3.1.0 that may cause class
conflict, and use indirectly dependencies from spring-boot-starter-*
* Polish apache/incubator-dubbo-spring-boot-project#341
* Add the samples
* Add a license
* Add the samples of Zookeeper and Nacos
* Update README.md
* Fix the test cases
---
README.md | 274 +++++++++------------
dubbo-spring-boot-autoconfigure/pom.xml | 2 +-
...oDefaultPropertiesEnvironmentPostProcessor.java | 20 ++
...DubboAutoConfigurationOnMultipleConfigTest.java | 4 +-
.../DubboAutoConfigurationOnSingleConfigTest.java | 5 +-
...aultPropertiesEnvironmentPostProcessorTest.java | 18 +-
dubbo-spring-boot-parent/pom.xml | 67 ++---
.../consumer-sample/pom.xml | 93 +++++++
.../DubboRegistryNacosConsumerBootstrap.java | 50 ++++
.../src/main/resources/application.yml | 11 +
.../{ => dubbo-registry-nacos-samples}/pom.xml | 34 +--
.../provider-sample/pom.xml | 94 +++++++
.../DubboRegistryNacosProviderBootstrap.java | 39 +++
.../demo/provider/service/DefaultDemoService.java | 42 ++++
.../src/main/resources/application.properties | 20 ++
.../consumer-sample/pom.xml | 79 ++++++
.../DubboRegistryZooKeeperConsumerBootstrap.java | 50 ++++
.../src/main/resources/application.yml | 15 ++
.../{ => dubbo-registry-zookeeper-samples}/pom.xml | 34 +--
.../provider-sample/pom.xml | 88 +++++++
.../DubboRegistryZooKeeperProviderBootstrap.java | 47 ++++
.../demo/provider/bootstrap/EmbeddedZooKeeper.java | 252 +++++++++++++++++++
.../demo/provider/service/DefaultDemoService.java | 42 ++++
.../src/main/resources/application.properties | 22 ++
dubbo-spring-boot-samples/pom.xml | 3 +
25 files changed, 1151 insertions(+), 254 deletions(-)
diff --git a/README.md b/README.md
index 1d90f7a..34ca0d3 100644
--- a/README.md
+++ b/README.md
@@ -20,24 +20,50 @@
You can introduce the latest `dubbo-spring-boot-starter` to your project by
adding the following dependency to your pom.xml
```xml
-<dependency>
- <groupId>com.alibaba.boot</groupId>
- <artifactId>dubbo-spring-boot-starter</artifactId>
- <version>0.2.1-SNAPSHOT</version>
-</dependency>
-
-<!-- Dubbo -->
-<dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>dubbo</artifactId>
- <version>2.6.5</version>
-</dependency>
-<!-- Spring Context Extras -->
-<dependency>
- <groupId>com.alibaba.spring</groupId>
- <artifactId>spring-context-support</artifactId>
- <version>1.0.2</version>
-</dependency>
+<properties>
+ <spring-boot.version>2.1.1.RELEASE</spring-boot.version>
+ <dubbo.version>2.6.5</dubbo.version>
+</properties>
+
+<dependencyManagement>
+ <dependencies>
+ <!-- Spring Boot -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring-boot.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
+ <!-- Dubbo dependencies -->
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>dubbo-dependencies-bom</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+</dependencyManagement>
+
+<dependencies>
+ <!-- Dubbo Spring Boot Starter -->
+ <dependency>
+ <groupId>com.alibaba.boot</groupId>
+ <artifactId>dubbo-spring-boot-starter</artifactId>
+ <version>0.2.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>dubbo</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-all</artifactId>
+ </dependency>
+</dependencies>
```
If your project failed to resolve the dependency, try to add the following
repository:
@@ -78,7 +104,7 @@ If you'd like to attempt to experience latest features, you
also can build from
| versions | Java | Spring Boot | Dubbo |
| -------- | ----- | ----------- | ---------- |
-| `0.2.0` | 1.8+ | `2.0.x` | `2.6.2` + |
+| `0.2.1` | 1.8+ | `2.1.x` | `2.6.2` + |
| `0.1.1` | 1.7+ | `1.5.x` | `2.6.2` + |
@@ -103,148 +129,108 @@ public interface DemoService {
### Dubbo service(s) provider
-Service Provider implements `DemoService`:
-
-```java
-@Service(
- version = "1.0.0",
- application = "${dubbo.application.id}",
- protocol = "${dubbo.protocol.id}",
- registry = "${dubbo.registry.id}"
-)
-public class DefaultDemoService implements DemoService {
-
- public String sayHello(String name) {
- return "Hello, " + name + " (from Spring Boot)";
- }
-
-}
-```
-
+1. Service Provider implements `DemoService`
+ ```java
+ @Service(version = "1.0.0")
+ public class DefaultDemoService implements DemoService {
-then, provides a bootstrap class:
-
-```java
-@SpringBootApplication
-public class DubboProviderDemo {
-
- public static void main(String[] args) {
-
- SpringApplication.run(DubboProviderDemo.class,args);
+ /**
+ * 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);
+ }
}
+ ```
-}
-```
-
+2. Provides a bootstrap class
+ ```java
+ @EnableAutoConfiguration
+ public class DubboProviderDemo {
-last, configures `application.properties`:
-
-```properties
-# Spring boot application
-spring.application.name = dubbo-provider-demo
-server.port = 9090
-management.port = 9091
-
-# 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.id = dubbo-provider-demo
-dubbo.application.name = dubbo-provider-demo
-
-## ProtocolConfig Bean
-dubbo.protocol.id = dubbo
-dubbo.protocol.name = dubbo
-dubbo.protocol.port = 12345
-
-## RegistryConfig Bean
-dubbo.registry.id = my-registry
-dubbo.registry.address = N/A
-```
+ public static void main(String[] args) {
+ SpringApplication.run(DubboProviderDemo.class,args);
+ }
+ }
+ ```
+3. Configures the `application.properties`:
+ ```properties
+ # Spring boot application
+ spring.application.name=dubbo-auto-configuration-provider-demo
-`DefaultDemoService`'s placeholders( `${dubbo.application.id}`,
`${dubbo.protocol.id}`, `${dubbo.registry.id}` ) sources from
`application.properties`.
+ # 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
-More details, please refer to [Dubbo Provider
Sample](dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider).
+ ## Dubbo Registry
+ dubbo.registry.address=N/A
+ ```
### Dubbo service(s) consumer
+1. Service consumer also provides a bootstrap class to reference `DemoService`
+ ```java
+ @EnableAutoConfiguration
+ public class DubboConsumerBootstrap {
-Service consumer requires Spring Beans to reference `DemoService`:
-
-```java
-@RestController
-public class DemoConsumerController {
-
- @Reference(version = "1.0.0",
- application = "${dubbo.application.id}",
- url = "dubbo://localhost:12345")
- private DemoService demoService;
-
- @RequestMapping("/sayHello")
- public String sayHello(@RequestParam String name) {
- return demoService.sayHello(name);
- }
-
-}
-```
-
-
-
-then, also provide a bootstrap class:
-
-```java
-@SpringBootApplication(scanBasePackages =
"com.alibaba.boot.dubbo.demo.consumer.controller")
-public class DubboConsumerDemo {
+ private final Logger logger = LoggerFactory.getLogger(getClass());
- public static void main(String[] args) {
+ @Reference(version = "1.0.0", url = "dubbo://localhost:12345")
+ private DemoService demoService;
- SpringApplication.run(DubboConsumerDemo.class,args);
+ @Bean
+ public ApplicationRunner runner() {
+ return args -> {
+ logger.info(demoService.sayHello("mercyblitz"));
+ };
+ }
+ public static void main(String[] args) {
+ SpringApplication.run(DubboConsumerBootstrap.class).close();
+ }
}
+ ```
-}
-```
-
-
+2. configures `application.properties`
-last, configures `application.properties`:
+ ```properties
+ # Spring boot application
+ spring.application.name = dubbo-consumer-demo
+ server.port = 8080
+ management.port = 8081
-```properties
-# Spring boot application
-spring.application.name = dubbo-consumer-demo
-server.port = 8080
-management.port = 8081
+ # Dubbo Config properties
+ ## ApplicationConfig Bean
+ dubbo.application.id = dubbo-consumer-demo
+ dubbo.application.name = dubbo-consumer-demo
-# Dubbo Config properties
-## ApplicationConfig Bean
-dubbo.application.id = dubbo-consumer-demo
-dubbo.application.name = dubbo-consumer-demo
-
-## ProtocolConfig Bean
-dubbo.protocol.id = dubbo
-dubbo.protocol.name = dubbo
-dubbo.protocol.port = 12345
-```
-
+ ## ProtocolConfig Bean
+ dubbo.protocol.id = dubbo
+ dubbo.protocol.name = dubbo
+ dubbo.protocol.port = 12345
+ ```
+If `DubboProviderDemo` works well, please mark sure `DubboProviderDemo` is
started.
-If `DubboProviderDemo` works well, please mark sure Dubbo service(s) is active.
-
-
-
-More details, please refer to [Dubbo Consumer
Sample](dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer)
+More details, please refer to [Samples](dubbo-spring-boot-samples).
@@ -261,7 +247,7 @@ Having trouble with Dubbo Spring Boot? We’d like to help!
## Building from Source
-If you want to try out thr latest features of Dubbo Spring Boot, it can be
easily built with the [maven wrapper](https://github.com/takari/maven-wrapper).
Your JDK is 1.7 or above.
+If you want to try out thr latest features of Dubbo Spring Boot, it can be
easily built with the [maven wrapper](https://github.com/takari/maven-wrapper).
Your JDK is 1.8 or above.
```
$ ./mvnw clean install
@@ -301,24 +287,10 @@ The main usage of `dubbo-spring-boot-parent` is providing
dependencies managemen
### [dubbo-spring-boot-samples](dubbo-spring-boot-samples)
-The samples project of Dubbo Spring Boot that includes two parts:
-
-
-
-#### [Dubbo Provider
Sample](dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider)
-
-Dubbo Service will be exported on localhost with port `12345`.
-
-* [Health Checks](dubbo-spring-boot-actuator#health-checks):
http://localhost:9091/health
-* [Dubbo Endpoint](dubbo-spring-boot-actuator#endpoints):
http://localhost:9091/dubbo
-
-
-
-#### [Dubbo Consumer
Sample](dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer)
-
-Dubbo Service will be consumed at Spring WebMVC `Controller`.
-
-* Demo `Controller`: http://localhost:8080/sayHello?name=HelloWorld
-* [Health Checks](dubbo-spring-boot-actuator#health-checks):
http://localhost:8081/actuator/health
-* [Dubbo Endpoint](dubbo-spring-boot-actuator#endpoints):
http://localhost:8081/actuator/dubbo
+The samples project of Dubbo Spring Boot that includes:
+- [Auto-Configuaration
Samples](dubbo-spring-boot-samples/auto-configure-samples)
+- [Externalized Configuration
Samples](dubbo-spring-boot-samples/externalized-configuration-samples)
+- [Registry Zookeeper
Samples](dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples)
+- [Registry Nacos
Samples](dubbo-spring-boot-samples/dubbo-registry-nacos-samples)
+- [Sample API](dubbo-spring-boot-samples/sample-api)
\ No newline at end of file
diff --git a/dubbo-spring-boot-autoconfigure/pom.xml
b/dubbo-spring-boot-autoconfigure/pom.xml
index a7a7a34..6fb2ea3 100644
--- a/dubbo-spring-boot-autoconfigure/pom.xml
+++ b/dubbo-spring-boot-autoconfigure/pom.xml
@@ -21,7 +21,7 @@
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-parent</artifactId>
<version>0.2.1-SNAPSHOT</version>
- <relativePath>../dubbo-spring-boot-parent</relativePath>
+ <relativePath>../dubbo-spring-boot-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
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 d8a671b..3292bf9 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 class DubboDefaultPropertiesEnvironmentPostProcessor
implements Environme
private Map<String, Object>
createDefaultProperties(ConfigurableEnvironment environment) {
Map<String, Object> defaultProperties = new HashMap<String, Object>();
setDubboApplicationNameProperty(environment, defaultProperties);
+ setDubboConfigMultipleProperty(defaultProperties);
+ setDubboApplicationQosEnableProperty(defaultProperties);
return defaultProperties;
}
@@ -92,6 +104,14 @@ public class DubboDefaultPropertiesEnvironmentPostProcessor
implements Environme
}
}
+ private void setDubboConfigMultipleProperty(Map<String, Object>
defaultProperties) {
+ defaultProperties.put(DUBBO_CONFIG_MULTIPLE_PROPERTY,
Boolean.TRUE.toString());
+ }
+
+ private void setDubboApplicationQosEnableProperty(Map<String, Object>
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 af38587..4163ac0 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
@@ -153,7 +153,7 @@ public class DubboAutoConfigurationOnMultipleConfigTest {
public void testMultipleDubboConfigBindingProperties() {
- Assert.assertEquals(2, applications.size());
+ Assert.assertEquals(3, applications.size());
Assert.assertEquals(1, modules.size());
@@ -177,7 +177,7 @@ public class DubboAutoConfigurationOnMultipleConfigTest {
*/
Map<String, ApplicationConfig> 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 b60340e..7f4cd5e 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
@@ -39,7 +39,6 @@ import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* {@link DubboAutoConfiguration} Test On single Dubbo Configuration
*
- *
* @since 1.0.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@@ -151,7 +150,7 @@ public class DubboAutoConfigurationOnSingleConfigTest {
@Test
public void testMultipleDubboConfigConfiguration() {
- Assert.assertNull(multipleDubboConfigConfiguration);
+ Assert.assertNotNull(multipleDubboConfigConfiguration);
}
@Test
@@ -161,7 +160,7 @@ public class DubboAutoConfigurationOnSingleConfigTest {
@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 626f2c9..d941a4f 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 class
DubboDefaultPropertiesEnvironmentPostProcessorTest {
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 class
DubboDefaultPropertiesEnvironmentPostProcessorTest {
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 class
DubboDefaultPropertiesEnvironmentPostProcessorTest {
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<String, Object>()));
+ 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 82ab700..5b5d29e 100644
--- a/dubbo-spring-boot-parent/pom.xml
+++ b/dubbo-spring-boot-parent/pom.xml
@@ -39,9 +39,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.1.1.RELEASE</spring-boot.version>
<dubbo.version>2.6.5</dubbo.version>
- <zkclient.version>0.2</zkclient.version>
- <zookeeper.version>3.4.9</zookeeper.version>
- <curator-framework.version>2.12.0</curator-framework.version>
+ <dubbo-registry-nacos.version>0.0.2</dubbo-registry-nacos.version>
+ <nacos-client.version>0.6.2</nacos-client.version>
<!-- Build args -->
<argline>-server -Xms256m -Xmx512m -XX:PermSize=64m
-XX:MaxPermSize=128m -Dfile.encoding=UTF-8
-Djava.net.preferIPv4Stack=true
@@ -62,7 +61,6 @@
<dependencyManagement>
<dependencies>
-
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -72,6 +70,15 @@
<scope>import</scope>
</dependency>
+ <!-- Dubbo dependencies -->
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>dubbo-dependencies-bom</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
<!-- Dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
@@ -93,54 +100,18 @@
</exclusions>
</dependency>
- <!-- Alibaba Spring Context extension -->
+ <!-- Dubbo Nacos registry dependency -->
<dependency>
- <groupId>com.alibaba.spring</groupId>
- <artifactId>spring-context-support</artifactId>
- <version>${alibaba-spring-context-support.version}</version>
- </dependency>
-
- <!-- ZK -->
- <dependency>
- <groupId>org.apache.zookeeper</groupId>
- <artifactId>zookeeper</artifactId>
- <version>${zookeeper.version}</version>
- <exclusions>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </exclusion>
- <exclusion>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>com.101tec</groupId>
- <artifactId>zkclient</artifactId>
- <version>${zkclient.version}</version>
- <exclusions>
- <exclusion>
- <artifactId>slf4j-api</artifactId>
- <groupId>org.slf4j</groupId>
- </exclusion>
- <exclusion>
- <artifactId>log4j</artifactId>
- <groupId>log4j</groupId>
- </exclusion>
- <exclusion>
- <artifactId>slf4j-log4j12</artifactId>
- <groupId>org.slf4j</groupId>
- </exclusion>
- </exclusions>
+ <groupId>com.alibaba</groupId>
+ <artifactId>dubbo-registry-nacos</artifactId>
+ <version>${dubbo-registry-nacos.version}</version>
</dependency>
+ <!-- Keep latest Nacos client version -->
<dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-framework</artifactId>
- <version>${curator-framework.version}</version>
+ <groupId>com.alibaba.nacos</groupId>
+ <artifactId>nacos-client</artifactId>
+ <version>${nacos-client.version}</version>
</dependency>
</dependencies>
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 0000000..1da62fc
--- /dev/null
+++
b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/pom.xml
@@ -0,0 +1,93 @@
+<!--
+ 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.
+ -->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>com.alibaba.boot.samples</groupId>
+ <artifactId>dubbo-spring-boot-registry-nacos-samples</artifactId>
+ <version>0.2.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dubbo-spring-boot-registry-nacos-consumer-sample</artifactId>
+ <name>Dubbo Spring Boot Samples : Registry Nacos :: Consumer Sample</name>
+
+ <dependencies>
+ <!-- Spring Boot dependencies -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.alibaba.boot</groupId>
+ <artifactId>dubbo-spring-boot-starter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- Dubbo -->
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>dubbo</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>dubbo-spring-boot-sample-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- Netty -->
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-all</artifactId>
+ </dependency>
+
+ <!-- Dubbo Nacos registry dependency -->
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>dubbo-registry-nacos</artifactId>
+ </dependency>
+
+ <!-- Keep latest Nacos client version -->
+ <dependency>
+ <groupId>com.alibaba.nacos</groupId>
+ <artifactId>nacos-client</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring-boot.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ 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 0000000..408fe5e
--- /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,50 @@
+/*
+ * 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.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 args -> {
+ 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 0000000..7889cf7
--- /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/pom.xml
b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/pom.xml
similarity index 52%
copy from dubbo-spring-boot-samples/pom.xml
copy to dubbo-spring-boot-samples/dubbo-registry-nacos-samples/pom.xml
index 07be5f4..a9c3995 100644
--- a/dubbo-spring-boot-samples/pom.xml
+++ b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/pom.xml
@@ -14,37 +14,25 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
- <groupId>com.alibaba.boot</groupId>
- <artifactId>dubbo-spring-boot-parent</artifactId>
+ <groupId>com.alibaba.boot.samples</groupId>
+ <artifactId>dubbo-spring-boot-samples</artifactId>
<version>0.2.1-SNAPSHOT</version>
- <relativePath>../dubbo-spring-boot-parent/pom.xml</relativePath>
+ <relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
- <groupId>com.alibaba.boot.samples</groupId>
- <artifactId>dubbo-spring-boot-samples</artifactId>
+ <artifactId>dubbo-spring-boot-registry-nacos-samples</artifactId>
+ <name>Dubbo Spring Boot Samples : Registry Nacos</name>
+ <description>Dubbo Spring Boot Registry Nacos Samples</description>
<packaging>pom</packaging>
- <name>Dubbo Spring Boot Samples</name>
- <description>Dubbo Spring Boot Samples</description>
+
<modules>
- <module>sample-api</module>
- <module>auto-configure-samples</module>
- <module>externalized-configuration-samples</module>
+ <module>consumer-sample</module>
+ <module>provider-sample</module>
</modules>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-deploy-plugin</artifactId>
- <configuration>
- <skip>true</skip>
- </configuration>
- </plugin>
- </plugins>
- </build>
</project>
\ 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 0000000..899b263
--- /dev/null
+++
b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/pom.xml
@@ -0,0 +1,94 @@
+<!--
+ 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.
+ -->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>com.alibaba.boot.samples</groupId>
+ <artifactId>dubbo-spring-boot-registry-nacos-samples</artifactId>
+ <version>0.2.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dubbo-spring-boot-registry-nacos-provider-sample</artifactId>
+ <name>Dubbo Spring Boot Samples : Registry Nacos :: Provider Sample</name>
+
+ <dependencies>
+
+ <!-- Spring Boot dependencies -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.alibaba.boot</groupId>
+ <artifactId>dubbo-spring-boot-starter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- Dubbo -->
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>dubbo</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>dubbo-spring-boot-sample-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- Netty -->
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-all</artifactId>
+ </dependency>
+
+ <!-- Dubbo Nacos registry dependency -->
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>dubbo-registry-nacos</artifactId>
+ </dependency>
+
+ <!-- Keep latest Nacos client version -->
+ <dependency>
+ <groupId>com.alibaba.nacos</groupId>
+ <artifactId>nacos-client</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring-boot.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+
+</project>
\ 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 0000000..361a392
--- /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,39 @@
+/*
+ * 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.WebApplicationType;
+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(WebApplicationType.NONE)
+ .run();
+ }
+}
diff --git
a/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java
b/dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java
new file mode 100644
index 0000000..f1d9ae1
--- /dev/null
+++
b/dubbo-spring-boot-samples/dubbo-registry-nacos-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-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 0000000..91635fb
--- /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-registry-zookeeper-samples/consumer-sample/pom.xml
b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/pom.xml
new file mode 100644
index 0000000..cbf9b36
--- /dev/null
+++
b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/pom.xml
@@ -0,0 +1,79 @@
+<!--
+ 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.
+ -->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>com.alibaba.boot.samples</groupId>
+ <artifactId>dubbo-spring-boot-registry-zookeeper-samples</artifactId>
+ <version>0.2.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+
<artifactId>dubbo-spring-boot-registry-zookeeper-consumer-sample</artifactId>
+ <name>Dubbo Spring Boot Samples : Registry Zookeeper :: Consumer
Sample</name>
+ <dependencies>
+
+ <!-- Spring Boot dependencies -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.alibaba.boot</groupId>
+ <artifactId>dubbo-spring-boot-starter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>dubbo</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>dubbo-spring-boot-sample-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-framework</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring-boot.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ 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 0000000..1b7935b
--- /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,50 @@
+/*
+ * 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.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 args -> {
+ 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 0000000..88846fb
--- /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/pom.xml
b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/pom.xml
similarity index 52%
copy from dubbo-spring-boot-samples/pom.xml
copy to dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/pom.xml
index 07be5f4..a07218d 100644
--- a/dubbo-spring-boot-samples/pom.xml
+++ b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/pom.xml
@@ -14,37 +14,25 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
- <groupId>com.alibaba.boot</groupId>
- <artifactId>dubbo-spring-boot-parent</artifactId>
+ <groupId>com.alibaba.boot.samples</groupId>
+ <artifactId>dubbo-spring-boot-samples</artifactId>
<version>0.2.1-SNAPSHOT</version>
- <relativePath>../dubbo-spring-boot-parent/pom.xml</relativePath>
+ <relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
- <groupId>com.alibaba.boot.samples</groupId>
- <artifactId>dubbo-spring-boot-samples</artifactId>
+ <artifactId>dubbo-spring-boot-registry-zookeeper-samples</artifactId>
+ <name>Dubbo Spring Boot Samples : Registry Zookeeper</name>
+ <description>Dubbo Spring Boot Registry Zookeeper Samples</description>
<packaging>pom</packaging>
- <name>Dubbo Spring Boot Samples</name>
- <description>Dubbo Spring Boot Samples</description>
+
<modules>
- <module>sample-api</module>
- <module>auto-configure-samples</module>
- <module>externalized-configuration-samples</module>
+ <module>consumer-sample</module>
+ <module>provider-sample</module>
</modules>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-deploy-plugin</artifactId>
- <configuration>
- <skip>true</skip>
- </configuration>
- </plugin>
- </plugins>
- </build>
</project>
\ 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 0000000..eba5f19
--- /dev/null
+++
b/dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/pom.xml
@@ -0,0 +1,88 @@
+<!--
+ 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.
+ -->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>com.alibaba.boot.samples</groupId>
+ <artifactId>dubbo-spring-boot-registry-zookeeper-samples</artifactId>
+ <version>0.2.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+
<artifactId>dubbo-spring-boot-registry-zookeeper-provider-sample</artifactId>
+ <name>Dubbo Spring Boot Samples : Registry Zookeeper :: Provider
Sample</name>
+
+ <dependencies>
+
+ <!-- Spring Boot dependencies -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.alibaba.boot</groupId>
+ <artifactId>dubbo-spring-boot-starter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- Dubbo -->
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>dubbo</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>dubbo-spring-boot-sample-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- Zookeeper -->
+ <dependency>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-framework</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring-boot.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+
+</project>
\ 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 0000000..bcc9407
--- /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,47 @@
+/*
+ * 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.WebApplicationType;
+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(WebApplicationType.NONE)
+
.listeners((ApplicationListener<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 0000000..ced6344
--- /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
+ * <p>
+ * Helper class to start an embedded instance of standalone (non clustered)
ZooKeeper.
+ * <p>
+ * 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.
+ * <p>
+ * 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 0000000..f1d9ae1
--- /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 0000000..30aa324
--- /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/pom.xml
b/dubbo-spring-boot-samples/pom.xml
index 07be5f4..3a8a9be 100644
--- a/dubbo-spring-boot-samples/pom.xml
+++ b/dubbo-spring-boot-samples/pom.xml
@@ -30,10 +30,13 @@
<packaging>pom</packaging>
<name>Dubbo Spring Boot Samples</name>
<description>Dubbo Spring Boot Samples</description>
+
<modules>
<module>sample-api</module>
<module>auto-configure-samples</module>
<module>externalized-configuration-samples</module>
+ <module>dubbo-registry-nacos-samples</module>
+ <module>dubbo-registry-zookeeper-samples</module>
</modules>
<build>