You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2019/01/16 08:38:05 UTC

[servicecomb-java-chassis] Diff for: [GitHub] liubao68 merged pull request #1058: [SCB-1109] local-service-registry sample of java-chassis can not run directly

diff --git a/samples/local-service-registry/README.md b/samples/local-service-registry/README.md
old mode 100644
new mode 100755
index 2b2d69463..8b7c28b8c
--- a/samples/local-service-registry/README.md
+++ b/samples/local-service-registry/README.md
@@ -33,13 +33,14 @@ Please find the details as follows.
 ```java
     public class xxxClient {
       public static void main(String[] args) {
-      System.setProperty("local.registry.file", "/yourpath/registry.yaml");
-        //your code
-      System.clearProperty("local.registry.file");
+      //"yourregistry.yaml" should be put in resource directory
+      System.setProperty("local.registry.file", "yourregistry.yaml");
+
+      //your code
       }
     }
 ```
-   If file present in this path "local.registry.file" then registry mode is Local registry mode. It will not connect to service center.
+   if file present in this path "local.registry.file" then registry mode is Local registry mode. It will not connect to service center.
 
 * Add provider's schema file at below location of consumer side
 
diff --git a/samples/local-service-registry/local-registry-client/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryclient/LocalRegistryClient.java b/samples/local-service-registry/local-registry-client/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryclient/LocalRegistryClient.java
old mode 100644
new mode 100755
index 3d261747c..9b30d8105
--- a/samples/local-service-registry/local-registry-client/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryclient/LocalRegistryClient.java
+++ b/samples/local-service-registry/local-registry-client/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryclient/LocalRegistryClient.java
@@ -30,7 +30,8 @@
   private static RestTemplate templateNew = RestTemplateBuilder.create();
 
   public static void main(String[] args) throws Exception {
-    System.setProperty("local.registry.file", "src/main/resources/registry.yaml");
+    System.setProperty("local.registry.file", "registry.yaml");
+
     init();
 
     run();
diff --git a/samples/local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryserver/LocalRegistryServer.java b/samples/local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryserver/LocalRegistryServer.java
index 82151d9b2..4e208fee1 100644
--- a/samples/local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryserver/LocalRegistryServer.java
+++ b/samples/local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryserver/LocalRegistryServer.java
@@ -22,7 +22,8 @@
 
 public class LocalRegistryServer {
   public static void main(String[] args) throws Exception {
-    System.setProperty("local.registry.file", "src/main/resources/registry.yaml");
+    System.setProperty("local.registry.file", "notExistJustForceLocal");
+
     Log4jUtils.init();
     BeanUtils.init();
   }
diff --git a/samples/local-service-registry/local-registry-server/src/main/resources/registry.yaml b/samples/local-service-registry/local-registry-server/src/main/resources/registry.yaml
deleted file mode 100644
index 446814cf6..000000000
--- a/samples/local-service-registry/local-registry-server/src/main/resources/registry.yaml
+++ /dev/null
@@ -1,25 +0,0 @@
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-
-localserv:
-  - id: "100"
-    version: "0.0.2"
-    appid: localservreg
-    instances:
-      - endpoints:
-        - rest://localhost:8080
-        - highway://localhost:7070
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
old mode 100644
new mode 100755
index 201ceb5f5..6b96b686d
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
@@ -78,16 +78,12 @@ public LocalServiceRegistryClientImpl() {
       return;
     }
 
-    File file = new File(LOCAL_REGISTRY_FILE);
-    if (!file.exists()) {
+    InputStream is = this.getClass().getClassLoader().getResourceAsStream(LOCAL_REGISTRY_FILE);
+    if (is == null) {
       return;
     }
 
-    try (InputStream is = new FileInputStream(file)) {
-      initFromData(is);
-    } catch (IOException e) {
-      LOGGER.error("can not load local registry file:" + LOCAL_REGISTRY_FILE, e);
-    }
+    initFromData(is);
   }
 
   public LocalServiceRegistryClientImpl(InputStream is) {


With regards,
Apache Git Services