You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2019/01/16 08:38:06 UTC
[servicecomb-java-chassis] branch master updated: [SCB-1109]
local-service-registry sample of java-chassis can not run directly
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 80e66de [SCB-1109] local-service-registry sample of java-chassis can not run directly
80e66de is described below
commit 80e66de8585b233ff1d1fb50634f2b2e207da8a6
Author: MabinGo <bi...@huawei.com>
AuthorDate: Fri Jan 11 10:27:32 2019 +0800
[SCB-1109] local-service-registry sample of java-chassis can not run directly
Signed-off-by: MabinGo <bi...@huawei.com>
---
samples/local-service-registry/README.md | 9 ++++----
.../localregistryclient/LocalRegistryClient.java | 3 ++-
.../localregistryserver/LocalRegistryServer.java | 3 ++-
.../src/main/resources/registry.yaml | 25 ----------------------
.../client/LocalServiceRegistryClientImpl.java | 10 +++------
5 files changed, 12 insertions(+), 38 deletions(-)
diff --git a/samples/local-service-registry/README.md b/samples/local-service-registry/README.md
old mode 100644
new mode 100755
index 2b2d694..8b7c28b
--- 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 3d26174..9b30d81
--- 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 @@ 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");
+ 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 82151d9..4e208fe 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 @@ import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
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 446814c..0000000
--- 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 201ceb5..6b96b68
--- 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 class LocalServiceRegistryClientImpl implements ServiceRegistryClient {
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) {