This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git


The following commit(s) were added to refs/heads/master by this push:
     new 9a037b2  add default config sample (#132)
9a037b2 is described below

commit 9a037b2ff3dfec49bc73c5a4e068548cc7f26501
Author: ken.lj <[email protected]>
AuthorDate: Wed Dec 18 22:24:49 2019 +0800

    add default config sample (#132)
---
 .../src/main/resources/log4j.properties            |   1 -
 java/dubbo-samples-default-config/pom.xml          | 139 ++++++++++++
 .../samples/multi/registry/EmbeddedZooKeeper.java  | 250 +++++++++++++++++++++
 .../multi/registry/MultiRegistryConsumer.java      |  42 ++++
 .../multi/registry/MultiRegistryProvider.java      |  39 ++++
 .../samples/multi/registry/api/DemoService.java    |  26 +++
 .../samples/multi/registry/api/HelloService.java   |  26 +++
 .../multi/registry/impl/DemoServiceImpl.java       |  30 +++
 .../multi/registry/impl/HelloServiceImpl.java      |  30 +++
 .../src/main/resources/log4j.properties            |   6 +-
 .../src/main/resources/spring/consumer.xml         |  44 ++++
 .../src/main/resources/spring/provider.xml         |  46 ++++
 java/pom.xml                                       |   1 +
 13 files changed, 676 insertions(+), 4 deletions(-)

diff --git a/java/dubbo-samples-annotation/src/main/resources/log4j.properties 
b/java/dubbo-samples-annotation/src/main/resources/log4j.properties
index 7232873..e976f5c 100644
--- a/java/dubbo-samples-annotation/src/main/resources/log4j.properties
+++ b/java/dubbo-samples-annotation/src/main/resources/log4j.properties
@@ -16,7 +16,6 @@
 #   limitations under the License.
 #  
 #
-
 ###set log levels###
 log4j.rootLogger=info, stdout
 ###output to the console###
diff --git a/java/dubbo-samples-default-config/pom.xml 
b/java/dubbo-samples-default-config/pom.xml
new file mode 100644
index 0000000..24093e7
--- /dev/null
+++ b/java/dubbo-samples-default-config/pom.xml
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <groupId>org.apache.dubbo</groupId>
+    <version>1.0-SNAPSHOT</version>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>dubbo-samples-default-config</artifactId>
+
+    <properties>
+        <source.level>1.8</source.level>
+        <target.level>1.8</target.level>
+        <dubbo.version>2.7.5-SNAPSHOT</dubbo.version>
+        <spring.version>4.3.16.RELEASE</spring.version>
+        <junit.version>4.12</junit.version>
+        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
+        <maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
+        <image.name>${project.artifactId}:${dubbo.version}</image.name>
+        <java-image.name>openjdk:8</java-image.name>
+        <dubbo.port>20890</dubbo.port>
+        <zookeeper.port.1>2181</zookeeper.port.1>
+        <zookeeper.port.2>2182</zookeeper.port.2>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo</artifactId>
+            <version>${dubbo.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-rpc-hessian</artifactId>
+            <version>${dubbo.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-dependencies-zookeeper</artifactId>
+            <version>${dubbo.version}</version>
+            <type>pom</type>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <profiles>
+        <profile>
+            <id>dubbo-integration-test</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.dubbo</groupId>
+                        <artifactId>dubbo-maven-address-plugin</artifactId>
+                        <version>1.0-SNAPSHOT</version>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>local-address</goal>
+                                </goals>
+                                <configuration>
+                                    
<localAddress>dubbo-local-address</localAddress>
+                                </configuration>
+                                <phase>initialize</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-failsafe-plugin</artifactId>
+                        <version>${maven-failsafe-plugin.version}</version>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>integration-test</goal>
+                                    <goal>verify</goal>
+                                </goals>
+                                <configuration>
+                                    <systemPropertyVariables>
+                                        
<zookeeper.address>${dubbo-local-address}</zookeeper.address>
+                                    </systemPropertyVariables>
+                                    <includes>
+                                        <include>**/*IT.java</include>
+                                    </includes>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>${maven-compiler-plugin.version}</version>
+                <configuration>
+                    <source>${source.level}</source>
+                    <target>${target.level}</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git 
a/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/EmbeddedZooKeeper.java
 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/EmbeddedZooKeeper.java
new file mode 100644
index 0000000..a906547
--- /dev/null
+++ 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/EmbeddedZooKeeper.java
@@ -0,0 +1,250 @@
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * Licensed 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 org.apache.dubbo.samples.multi.registry;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Properties;
+import java.util.UUID;
+
+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;
+
+/**
+ * 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
+ * {@link 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);
+                }
+            }
+        }
+    }
+
+}
\ No newline at end of file
diff --git 
a/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryConsumer.java
 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryConsumer.java
new file mode 100644
index 0000000..5e8158a
--- /dev/null
+++ 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryConsumer.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 org.apache.dubbo.samples.multi.registry;
+
+import org.apache.dubbo.samples.multi.registry.api.DemoService;
+import org.apache.dubbo.samples.multi.registry.api.HelloService;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+
+public class MultiRegistryConsumer {
+
+    public static void main(String[] args) throws Exception {
+        ClassPathXmlApplicationContext context = new 
ClassPathXmlApplicationContext("spring/consumer.xml");
+        context.start();
+
+        DemoService demoServiceFormBeijing = (DemoService) 
context.getBean("demoServiceFormBeijing");
+        HelloService helloServiceFormShanghai = (HelloService) 
context.getBean("helloServiceFormShanghai");
+        HelloService helloServiceFormBeijing = (HelloService) 
context.getBean("helloServiceFormBeijing");
+
+        System.out.println(demoServiceFormBeijing.get("service form beijing 
registry"));
+        System.out.println(helloServiceFormShanghai.sayHello("service form 
shanghai registry"));
+        System.out.println(helloServiceFormBeijing.sayHello("service form 
beijing registry"));
+    }
+}
diff --git 
a/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryProvider.java
 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryProvider.java
new file mode 100644
index 0000000..67cd5aa
--- /dev/null
+++ 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryProvider.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 org.apache.dubbo.samples.multi.registry;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.concurrent.CountDownLatch;
+
+
+public class MultiRegistryProvider {
+
+    public static void main(String[] args) throws Exception {
+        new EmbeddedZooKeeper(2181, false).start();
+        new EmbeddedZooKeeper(2182, false).start();
+
+        ClassPathXmlApplicationContext context = new 
ClassPathXmlApplicationContext("spring/provider.xml");
+        context.start();
+
+        System.out.println("dubbo service started");
+        new CountDownLatch(1).await();
+    }
+}
diff --git 
a/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/api/DemoService.java
 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/api/DemoService.java
new file mode 100644
index 0000000..10b7e3b
--- /dev/null
+++ 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/api/DemoService.java
@@ -0,0 +1,26 @@
+/*
+ *
+ *   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 org.apache.dubbo.samples.multi.registry.api;
+
+
+public interface DemoService {
+
+    String get(String name);
+}
diff --git 
a/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/api/HelloService.java
 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/api/HelloService.java
new file mode 100644
index 0000000..578ce97
--- /dev/null
+++ 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/api/HelloService.java
@@ -0,0 +1,26 @@
+/*
+ *
+ *   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 org.apache.dubbo.samples.multi.registry.api;
+
+
+public interface HelloService {
+
+    String sayHello(String name);
+}
diff --git 
a/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/impl/DemoServiceImpl.java
 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/impl/DemoServiceImpl.java
new file mode 100644
index 0000000..061f44f
--- /dev/null
+++ 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/impl/DemoServiceImpl.java
@@ -0,0 +1,30 @@
+/*
+ *
+ *   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 org.apache.dubbo.samples.multi.registry.impl;
+
+import org.apache.dubbo.samples.multi.registry.api.DemoService;
+
+
+public class DemoServiceImpl implements DemoService {
+
+    public String get(String name) {
+        return "get: " + name;
+    }
+}
diff --git 
a/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/impl/HelloServiceImpl.java
 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/impl/HelloServiceImpl.java
new file mode 100644
index 0000000..c039a41
--- /dev/null
+++ 
b/java/dubbo-samples-default-config/src/main/java/org/apache/dubbo/samples/multi/registry/impl/HelloServiceImpl.java
@@ -0,0 +1,30 @@
+/*
+ *
+ *   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 org.apache.dubbo.samples.multi.registry.impl;
+
+import org.apache.dubbo.samples.multi.registry.api.HelloService;
+
+
+public class HelloServiceImpl implements HelloService {
+
+    public String sayHello(String name) {
+        return "sayHello: " + name;
+    }
+}
diff --git a/java/dubbo-samples-annotation/src/main/resources/log4j.properties 
b/java/dubbo-samples-default-config/src/main/resources/log4j.properties
similarity index 96%
copy from java/dubbo-samples-annotation/src/main/resources/log4j.properties
copy to java/dubbo-samples-default-config/src/main/resources/log4j.properties
index 7232873..d6ecd5c 100644
--- a/java/dubbo-samples-annotation/src/main/resources/log4j.properties
+++ b/java/dubbo-samples-default-config/src/main/resources/log4j.properties
@@ -6,15 +6,15 @@
 #   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.
-#  
+#
 #
 
 ###set log levels###
diff --git 
a/java/dubbo-samples-default-config/src/main/resources/spring/consumer.xml 
b/java/dubbo-samples-default-config/src/main/resources/spring/consumer.xml
new file mode 100644
index 0000000..a502dca
--- /dev/null
+++ b/java/dubbo-samples-default-config/src/main/resources/spring/consumer.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo";
+       xmlns="http://www.springframework.org/schema/beans"; 
xmlns:context="http://www.springframework.org/schema/context";
+       xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://dubbo.apache.org/schema/dubbo 
http://dubbo.apache.org/schema/dubbo/dubbo.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd";>
+    <context:property-placeholder/>
+
+    <dubbo:application name="multi-registry-consumer"/>
+
+    <dubbo:registry id="beijingRegistry" 
address="zookeeper://${zookeeper.address:127.0.0.1}:2181" default="false"/>
+    <dubbo:registry id="shanghaiRegistry" 
address="zookeeper://${zookeeper.address:127.0.0.1}:2182"/>
+
+    <dubbo:consumer registry="beijingRegistry">
+        <dubbo:reference id="demoServiceFormBeijing"
+                         
interface="org.apache.dubbo.samples.multi.registry.api.DemoService"/>
+        <dubbo:reference id="helloServiceFormBeijing"
+                         
interface="org.apache.dubbo.samples.multi.registry.api.HelloService" 
protocol="hessian"/>
+    </dubbo:consumer>
+
+    <dubbo:consumer registry="shanghaiRegistry">
+        <dubbo:reference id="helloServiceFormShanghai"
+                         
interface="org.apache.dubbo.samples.multi.registry.api.HelloService"/>
+    </dubbo:consumer>
+
+</beans>
+
diff --git 
a/java/dubbo-samples-default-config/src/main/resources/spring/provider.xml 
b/java/dubbo-samples-default-config/src/main/resources/spring/provider.xml
new file mode 100644
index 0000000..7723dab
--- /dev/null
+++ b/java/dubbo-samples-default-config/src/main/resources/spring/provider.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo";
+       xmlns="http://www.springframework.org/schema/beans"; 
xmlns:context="http://www.springframework.org/schema/context";
+       xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://dubbo.apache.org/schema/dubbo 
http://dubbo.apache.org/schema/dubbo/dubbo.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd";>
+    <context:property-placeholder/>
+
+    <bean id="helloService" 
class="org.apache.dubbo.samples.multi.registry.impl.HelloServiceImpl"/>
+    <bean id="demoService" 
class="org.apache.dubbo.samples.multi.registry.impl.DemoServiceImpl"/>
+
+    <dubbo:application name="default-config-sample"/>
+
+    <dubbo:registry id="beijingRegistry" 
address="zookeeper://${zookeeper.address:127.0.0.1}:2181" default="false"/>
+    <dubbo:registry id="shanghaiRegistry" 
address="zookeeper://${zookeeper.address:127.0.0.1}:2182"/>
+
+    <dubbo:protocol name="dubbo" port="20890"/>
+    <dubbo:protocol name="hessian" port="8082"/>
+
+    <dubbo:provider id="defaultDubboCofig" protocol="dubbo,hessian" 
registry="beijingRegistry,shanghaiRegistry">
+        <dubbo:service 
interface="org.apache.dubbo.samples.multi.registry.api.HelloService" 
ref="helloService"/>
+    </dubbo:provider>
+
+    <dubbo:provider id="defaultHessianCofig" protocol="hessian" 
registry="beijingRegistry">
+        <dubbo:service 
interface="org.apache.dubbo.samples.multi.registry.api.DemoService" 
ref="demoService"/>
+    </dubbo:provider>
+
+
+</beans>
diff --git a/java/pom.xml b/java/pom.xml
index b3840de..7628e22 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -52,6 +52,7 @@
         <module>dubbo-samples-mock</module>
         <module>dubbo-samples-monitor</module>
         <module>dubbo-samples-multi-registry</module>
+        <module>dubbo-samples-default-config</module>
         <module>dubbo-samples-notify</module>
         <module>dubbo-samples-resilience4j</module>
         <module>dubbo-samples-rest</module>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to