[ 
https://issues.apache.org/jira/browse/SCB-985?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16665848#comment-16665848
 ] 

ASF GitHub Bot commented on SCB-985:
------------------------------------

yangbor closed pull request #969: [SCB-985] Add spring-boot2-starter-discovery
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/969
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/demo/demo-spring-boot-discovery/demo-spring-boot-zuul-proxy/pom.xml 
b/demo/demo-spring-boot-discovery/demo-spring-boot-zuul-proxy/pom.xml
index c2e0415cd..19473ddc6 100644
--- a/demo/demo-spring-boot-discovery/demo-spring-boot-zuul-proxy/pom.xml
+++ b/demo/demo-spring-boot-discovery/demo-spring-boot-zuul-proxy/pom.xml
@@ -31,6 +31,10 @@
     
<demo.main>org.apache.servicecomb.demo.discovery.zuul.DiscoveryZuulProxyIT.DiscoveryZuulProxy</demo.main>
   </properties>
   <dependencies>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.springframework.cloud</groupId>
       <artifactId>spring-cloud-starter-zuul</artifactId>
diff --git 
a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/config/impl/XmlLoader.java
 
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/config/impl/XmlLoader.java
index 4f95e2d5a..254b1eda3 100644
--- 
a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/config/impl/XmlLoader.java
+++ 
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/config/impl/XmlLoader.java
@@ -67,7 +67,7 @@ public XmlLoader(List<String> locationPatternList, String 
suffix) {
           }
 
           Element clone = (Element) doc.importNode(child, true);
-          Element exist = findAndSetExist((Element) clone);
+          Element exist = findAndSetExist(clone);
           if (exist == null) {
             root.appendChild(clone);
             continue;
diff --git a/java-chassis-dependencies-springboot2/pom.xml 
b/java-chassis-dependencies-springboot2/pom.xml
index 8f4884d64..8f68895b7 100644
--- a/java-chassis-dependencies-springboot2/pom.xml
+++ b/java-chassis-dependencies-springboot2/pom.xml
@@ -39,113 +39,41 @@
 
     <spring.version>5.0.4.RELEASE</spring.version>
     <spring.boot.version>2.0.0.RELEASE</spring.boot.version>
-    <spring.data.version>2.0.5.RELEASE</spring.data.version>
-    <spring.session.version>2.0.3.RELEASE</spring.session.version>
+    <spring.data.version>Kay-RELEASE</spring.data.version>
+    <spring.session.version>2.0.0.RELEASE</spring.session.version>
+    <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
   </properties>
 
   <dependencyManagement>
     <dependencies>
       <dependency>
-        <groupId>org.springframework.boot</groupId>
-        <artifactId>spring-boot-starter</artifactId>
-        <version>${spring.boot.version}</version>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-dependencies</artifactId>
+        <version>${spring-cloud.version}</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>
       <dependency>
         <groupId>org.springframework.boot</groupId>
-        <artifactId>spring-boot-starter-web</artifactId>
+        <artifactId>spring-boot-dependencies</artifactId>
         <version>${spring.boot.version}</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>
-
-      <dependency>
-        <groupId>org.springframework</groupId>
-        <artifactId>spring-context</artifactId>
-        <version>${spring.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.springframework</groupId>
-        <artifactId>spring-web</artifactId>
-        <version>${spring.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.springframework</groupId>
-        <artifactId>spring-webmvc</artifactId>
-        <version>${spring.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.springframework</groupId>
-        <artifactId>spring-aop</artifactId>
-        <version>${spring.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.springframework</groupId>
-        <artifactId>spring-aspects</artifactId>
-        <version>${spring.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.springframework</groupId>
-        <artifactId>spring-beans</artifactId>
-        <version>${spring.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.springframework</groupId>
-        <artifactId>spring-core</artifactId>
-        <version>${spring.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.springframework</groupId>
-        <artifactId>spring-expression</artifactId>
-        <version>${spring.version}</version>
-      </dependency>
       <dependency>
         <groupId>org.springframework</groupId>
-        <artifactId>spring-jdbc</artifactId>
-        <version>${spring.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.springframework</groupId>
-        <artifactId>spring-orm</artifactId>
-        <version>${spring.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.springframework</groupId>
-        <artifactId>spring-oxm</artifactId>
-        <version>${spring.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.springframework</groupId>
-        <artifactId>spring-tx</artifactId>
+        <artifactId>spring-framework-bom</artifactId>
         <version>${spring.version}</version>
+        <type>pom</type>
+        <scope>import</scope>
       </dependency>
 
       <dependency>
         <groupId>org.springframework.data</groupId>
-        <artifactId>spring-data-jpa</artifactId>
-        <version>${spring.data.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.springframework.data</groupId>
-        <artifactId>spring-data-commons</artifactId>
+        <artifactId>spring-data-releasetrain</artifactId>
         <version>${spring.data.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.springframework.data</groupId>
-        <artifactId>spring-data-keyvalue</artifactId>
-        <version>${spring.data.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.springframework.data</groupId>
-        <artifactId>spring-data-redis</artifactId>
-        <version>${spring.data.version}</version>
-      </dependency>
-
-      <dependency>
-        <groupId>org.springframework.session</groupId>
-        <artifactId>spring-session-data-redis</artifactId>
-        <version>${spring.session.version}</version>
+        <type>pom</type>
+        <scope>import</scope>
       </dependency>
 
       <dependency>
@@ -171,6 +99,11 @@
         <artifactId>spring-boot2-starter-standalone</artifactId>
         <version>1.1.0-SNAPSHOT</version>
       </dependency>
+      <dependency>
+        <groupId>org.apache.servicecomb</groupId>
+        <artifactId>spring-boot2-starter-discovery</artifactId>
+        <version>1.1.0-SNAPSHOT</version>
+      </dependency>
 
     </dependencies>
   </dependencyManagement>
diff --git a/spring-boot2-starter-parent/pom.xml 
b/spring-boot2-starter-parent/pom.xml
index ab0104d40..08f91172d 100644
--- a/spring-boot2-starter-parent/pom.xml
+++ b/spring-boot2-starter-parent/pom.xml
@@ -40,6 +40,7 @@
     <module>spring-boot2-starter</module>
     <module>spring-boot2-starter-servlet</module>
     <module>spring-boot2-starter-standalone</module>
+    <module>spring-boot2-starter-discovery</module>
   </modules>
 
   <build>
diff --git a/spring-boot2-starter-parent/spring-boot2-starter-discovery/pom.xml 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/pom.xml
new file mode 100644
index 000000000..3106b1670
--- /dev/null
+++ b/spring-boot2-starter-parent/spring-boot2-starter-discovery/pom.xml
@@ -0,0 +1,98 @@
+<!--
+  ~ 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";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.servicecomb</groupId>
+    <artifactId>spring-boot2-starter-parent</artifactId>
+    <version>1.1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>spring-boot2-starter-discovery</artifactId>
+  <name>Java Chassis::Spring Boot2 Starter::Discovery</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>ch.qos.logback</groupId>
+          <artifactId>logback-classic</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.slf4j</groupId>
+          <artifactId>log4j-over-slf4j</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework.cloud</groupId>
+      <artifactId>spring-cloud-commons</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework.cloud</groupId>
+      <artifactId>spring-cloud-context</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework.cloud</groupId>
+      <artifactId>spring-cloud-netflix-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework.cloud</groupId>
+      <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework.cloud</groupId>
+      <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>javax.ws.rs</groupId>
+          <artifactId>jsr311-api</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework.cloud</groupId>
+      <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jmockit</groupId>
+      <artifactId>jmockit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>service-registry</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>spring-boot2-starter</artifactId>
+    </dependency>
+  </dependencies>
+</project>
diff --git 
a/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseDiscoveryClient.java
 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseDiscoveryClient.java
new file mode 100644
index 000000000..ad605af26
--- /dev/null
+++ 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseDiscoveryClient.java
@@ -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.
+ */
+package org.apache.servicecomb.springboot2.starter.discovery;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.servicecomb.foundation.common.cache.VersionedCache;
+import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
+import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
+import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
+import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
+import org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext;
+import org.apache.servicecomb.serviceregistry.discovery.DiscoveryTree;
+import org.springframework.cloud.client.DefaultServiceInstance;
+import org.springframework.cloud.client.ServiceInstance;
+import org.springframework.cloud.client.discovery.DiscoveryClient;
+
+public class CseDiscoveryClient implements DiscoveryClient {
+  private Map<String, DiscoveryTree> discoveryTrees = new 
ConcurrentHashMapEx<>();
+
+  @Override
+  public String description() {
+    return "Spring Cloud CSE Discovery Client";
+  }
+
+  @Override
+  public List<ServiceInstance> getInstances(final String serviceId) {
+    DiscoveryContext context = new DiscoveryContext();
+    context.setInputParameters(serviceId);
+    DiscoveryTree discoveryTree = discoveryTrees.computeIfAbsent(serviceId, 
key -> {
+      return new DiscoveryTree();
+    });
+    VersionedCache serversVersionedCache = discoveryTree.discovery(context,
+        RegistryUtils.getAppId(),
+        serviceId,
+        DefinitionConst.VERSION_RULE_ALL);
+    Map<String, MicroserviceInstance> servers = serversVersionedCache.data();
+    List<ServiceInstance> instances = new ArrayList<>(servers.size());
+    for (MicroserviceInstance s : servers.values()) {
+      for (String endpoint : s.getEndpoints()) {
+        URIEndpointObject uri = new URIEndpointObject(endpoint);
+        instances.add(new DefaultServiceInstance(serviceId, uri.getHostOrIp(), 
uri.getPort(), uri.isSslEnabled()));
+      }
+    }
+    return instances;
+  }
+
+  @Override
+  public List<String> getServices() {
+    ServiceRegistryClient client = RegistryUtils.getServiceRegistryClient();
+    List<Microservice> services = client.getAllMicroservices();
+    List<String> serviceIDList = new ArrayList<>();
+    if (null != services && !services.isEmpty()) {
+      for (Microservice service : services) {
+        serviceIDList.add(service.getServiceName());
+      }
+    }
+    return serviceIDList;
+  }
+}
diff --git 
a/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseDiscoveryClientConfiguration.java
 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseDiscoveryClientConfiguration.java
new file mode 100644
index 000000000..c99befdda
--- /dev/null
+++ 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseDiscoveryClientConfiguration.java
@@ -0,0 +1,36 @@
+/*
+ * 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.servicecomb.springboot2.starter.discovery;
+
+import org.springframework.boot.autoconfigure.AutoConfigureBefore;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.cloud.client.discovery.DiscoveryClient;
+import 
org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.annotation.Order;
+
+@AutoConfigureBefore(SimpleDiscoveryClientAutoConfiguration.class)
+@Configuration
+public class CseDiscoveryClientConfiguration {
+  @Bean
+  @Order(5000)
+  @ConditionalOnProperty(value = "servicecomb.discoveryClient.enabled", 
havingValue = "true", matchIfMissing = true)
+  public DiscoveryClient cseDiscoveryClient() {
+    return new CseDiscoveryClient();
+  }
+}
diff --git 
a/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseRibbonClientConfiguration.java
 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseRibbonClientConfiguration.java
new file mode 100644
index 000000000..3ff1fd369
--- /dev/null
+++ 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseRibbonClientConfiguration.java
@@ -0,0 +1,40 @@
+/*
+ * 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.servicecomb.springboot2.starter.discovery;
+
+import org.springframework.context.annotation.Bean;
+
+import com.netflix.client.config.IClientConfig;
+import com.netflix.loadbalancer.Server;
+import com.netflix.loadbalancer.ServerList;
+
+/**
+ * Custom {@link org.springframework.cloud.netflix.ribbon.RibbonClient} 
configuration must not be
+ * scanned by spring.
+ *
+ * @see <a 
href="http://cloud.spring.io/spring-cloud-static/Camden.SR4/#_customizing_the_ribbon_client";>
+ * Customizing the Ribbon Client </a>
+ */
+public class CseRibbonClientConfiguration {
+  @Bean
+  public ServerList<Server> ribbonServerList(
+      IClientConfig config) {
+    ServiceCombServerList serverList = new ServiceCombServerList();
+    serverList.initWithNiwsConfig(config);
+    return serverList;
+  }
+}
diff --git 
a/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseRibbonConfiguration.java
 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseRibbonConfiguration.java
new file mode 100644
index 000000000..72f905eda
--- /dev/null
+++ 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseRibbonConfiguration.java
@@ -0,0 +1,34 @@
+/*
+ * 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.servicecomb.springboot2.starter.discovery;
+
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import 
org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration;
+import org.springframework.cloud.netflix.ribbon.RibbonClients;
+import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@EnableConfigurationProperties
+@ConditionalOnBean(SpringClientFactory.class)
+@AutoConfigureAfter(RibbonAutoConfiguration.class)
+@RibbonClients(defaultConfiguration = CseRibbonClientConfiguration.class)
+public class CseRibbonConfiguration {
+
+}
diff --git 
a/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseRibbonEndpointDiscoveryFilter.java
 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseRibbonEndpointDiscoveryFilter.java
new file mode 100644
index 000000000..8ab7d36fd
--- /dev/null
+++ 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/CseRibbonEndpointDiscoveryFilter.java
@@ -0,0 +1,45 @@
+/*
+ * 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.servicecomb.springboot2.starter.discovery;
+
+import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
+import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import 
org.apache.servicecomb.serviceregistry.discovery.AbstractEndpointDiscoveryFilter;
+import org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext;
+import org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode;
+
+import com.netflix.loadbalancer.Server;
+
+public class CseRibbonEndpointDiscoveryFilter extends 
AbstractEndpointDiscoveryFilter {
+  @Override
+  protected String findTransportName(DiscoveryContext context, 
DiscoveryTreeNode parent) {
+    //only need rest endpoints
+    return "rest";
+  }
+
+  @Override
+  protected Object createEndpoint(String transportName, String endpoint, 
MicroserviceInstance instance) {
+    URIEndpointObject uri = new URIEndpointObject(endpoint);
+    return new Server(uri.getHostOrIp(), uri.getPort());
+  }
+
+  @Override
+  public int getOrder() {
+    return (int) Short.MAX_VALUE - 1;
+  }
+}
diff --git 
a/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/ServiceCombServerList.java
 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/ServiceCombServerList.java
new file mode 100644
index 000000000..4592ea9d4
--- /dev/null
+++ 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/ServiceCombServerList.java
@@ -0,0 +1,61 @@
+/*
+ * 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.servicecomb.springboot2.starter.discovery;
+
+import java.util.List;
+
+import org.apache.servicecomb.foundation.common.cache.VersionedCache;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
+import org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext;
+import org.apache.servicecomb.serviceregistry.discovery.DiscoveryTree;
+
+import com.netflix.client.config.IClientConfig;
+import com.netflix.loadbalancer.AbstractServerList;
+import com.netflix.loadbalancer.Server;
+
+public class ServiceCombServerList extends AbstractServerList<Server> {
+
+  private DiscoveryTree discoveryTree = new DiscoveryTree();
+
+  private String serviceId;
+
+  public ServiceCombServerList() {
+    discoveryTree.addFilter(new CseRibbonEndpointDiscoveryFilter());
+  }
+
+  @Override
+  public List<Server> getInitialListOfServers() {
+    DiscoveryContext context = new DiscoveryContext();
+    context.setInputParameters(serviceId);
+    VersionedCache serversVersionedCache = discoveryTree.discovery(context,
+        RegistryUtils.getAppId(),
+        serviceId,
+        DefinitionConst.VERSION_RULE_ALL);
+    return serversVersionedCache.data();
+  }
+
+  @Override
+  public List<Server> getUpdatedListOfServers() {
+    return getInitialListOfServers();
+  }
+
+  @Override
+  public void initWithNiwsConfig(IClientConfig iClientConfig) {
+    this.serviceId = iClientConfig.getClientName();
+  }
+}
diff --git 
a/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/package-info.java
 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/package-info.java
new file mode 100644
index 000000000..0feb61311
--- /dev/null
+++ 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/java/org/apache/servicecomb/springboot2/starter/discovery/package-info.java
@@ -0,0 +1,17 @@
+/*
+ * 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.servicecomb.springboot2.starter.discovery;
diff --git 
a/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/resources/META-INF/spring.factories
 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/resources/META-INF/spring.factories
new file mode 100644
index 000000000..268f1129f
--- /dev/null
+++ 
b/spring-boot2-starter-parent/spring-boot2-starter-discovery/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,24 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+org.apache.servicecomb.springboot.starter.provider.EnableServiceComb=\
+  
org.apache.servicecomb.springboot2.starter.discovery.CseDiscoveryClientConfiguration,\
+  org.apache.servicecomb.springboot2.starter.discovery.CseRibbonConfiguration
+org.springframework.cloud.client.discovery.EnableDiscoveryClient=\
+  
org.apache.servicecomb.springboot2.starter.discovery.CseDiscoveryClientConfiguration
+org.springframework.cloud.netflix.ribbon.RibbonClient=\
+  org.apache.servicecomb.springboot2.starter.discovery.CseRibbonConfiguration
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Add springboot2-starter-discovery
> ---------------------------------
>
>                 Key: SCB-985
>                 URL: https://issues.apache.org/jira/browse/SCB-985
>             Project: Apache ServiceComb
>          Issue Type: Improvement
>          Components: Java-Chassis
>    Affects Versions: java-chassis-1.1.0
>            Reporter: Yang Bo
>            Assignee: Yang Bo
>            Priority: Major
>
> Copied springboot-starter-discovery to spritnboot2. Removed test code and 
> updated some spring-boot and spring-cloud versions.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to