From 6e6743ecd034b552b019b9573543a7add9d04bad Mon Sep 17 00:00:00 2001 From: MabinGo Date: Fri, 11 Jan 2019 10:27:32 +0800 Subject: [PATCH] Fix bug for local-service-registry Signed-off-by: MabinGo --- samples/local-service-registry/README.md | 8 ++++-- .../LocalRegistryClient.java | 6 ++++- .../LocalRegistryServer.java | 3 ++- .../src/main/resources/registry.yaml | 25 ------------------- 4 files changed, 13 insertions(+), 29 deletions(-) delete mode 100644 samples/local-service-registry/local-registry-server/src/main/resources/registry.yaml diff --git a/samples/local-service-registry/README.md b/samples/local-service-registry/README.md index 2b2d6946335..bb8be4c957a 100644 --- a/samples/local-service-registry/README.md +++ b/samples/local-service-registry/README.md @@ -33,13 +33,17 @@ Please find the details as follows. ```java public class xxxClient { public static void main(String[] args) { + //"yourpath" must be used absolute path    System.setProperty("local.registry.file", "/yourpath/registry.yaml"); - //your code + + //your code + ...... +    System.clearProperty("local.registry.file"); } } ``` - If file present in this path "local.registry.file" then registry mode is Local registry mode. It will not connect to service center. + File path must be used absolute path, 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 index 3d261747c60..4ee7f054487 100644 --- 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,10 +30,14 @@ public class LocalRegistryClient { private static RestTemplate templateNew = RestTemplateBuilder.create(); public static void main(String[] args) throws Exception { - System.setProperty("local.registry.file", "src/main/resources/registry.yaml"); + String absoluteFilePath = Class.class.getClass().getResource("/").getPath() + "registry.yaml"; + System.setProperty("local.registry.file", absoluteFilePath); + init(); run(); + + System.clearProperty("local.registry.file"); } public static void init() throws Exception { 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 82151d9b2f8..4e208fee123 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 446814cf61d..00000000000 --- 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