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 2018/10/27 09:01:31 UTC

[incubator-servicecomb-java-chassis] 01/02: [SCB-985] Add spring-boot2-starter-discovery

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/incubator-servicecomb-java-chassis.git

commit c4f1da5bc381719857be8cea99a96b78faa2a370
Author: Yang Bo <ya...@huawei.com>
AuthorDate: Fri Oct 26 11:24:23 2018 +0800

    [SCB-985] Add spring-boot2-starter-discovery
    
    The code is copied from springboot-starter-discovery and test code
    is removed. Adjusted the springboot and spring cloud versions for
    compatibility issues.
---
 .../demo-spring-boot-zuul-proxy/pom.xml            |  4 +
 java-chassis-dependencies-springboot2/pom.xml      | 50 +++++++++--
 spring-boot2-starter-parent/pom.xml                |  1 +
 .../spring-boot2-starter-discovery/pom.xml         | 98 ++++++++++++++++++++++
 .../starter/discovery/CseDiscoveryClient.java      | 79 +++++++++++++++++
 .../discovery/CseDiscoveryClientConfiguration.java | 36 ++++++++
 .../discovery/CseRibbonClientConfiguration.java    | 40 +++++++++
 .../starter/discovery/CseRibbonConfiguration.java  | 34 ++++++++
 .../CseRibbonEndpointDiscoveryFilter.java          | 45 ++++++++++
 .../starter/discovery/ServiceCombServerList.java   | 61 ++++++++++++++
 .../starter/discovery/package-info.java            | 17 ++++
 .../src/main/resources/META-INF/spring.factories   | 24 ++++++
 12 files changed, 484 insertions(+), 5 deletions(-)

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 c2e0415..19473dd 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
@@ -32,6 +32,10 @@
   </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>
     </dependency>
diff --git a/java-chassis-dependencies-springboot2/pom.xml b/java-chassis-dependencies-springboot2/pom.xml
index 8f4884d..f84e873 100644
--- a/java-chassis-dependencies-springboot2/pom.xml
+++ b/java-chassis-dependencies-springboot2/pom.xml
@@ -37,10 +37,11 @@
     <argLine>-Dfile.encoding=UTF-8</argLine>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
-    <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.version>5.0.6.RELEASE</spring.version>
+    <spring.boot.version>2.0.3.RELEASE</spring.boot.version>
+    <spring.data.version>2.0.3.RELEASE</spring.data.version>
     <spring.session.version>2.0.3.RELEASE</spring.session.version>
+    <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
   </properties>
 
   <dependencyManagement>
@@ -147,6 +148,42 @@
         <artifactId>spring-session-data-redis</artifactId>
         <version>${spring.session.version}</version>
       </dependency>
+      <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-dependencies</artifactId>
+        <version>${spring-cloud.version}</version>
+      </dependency>
+
+      <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-commons</artifactId>
+        <version>2.0.0.RELEASE</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-context</artifactId>
+        <version>2.0.0.RELEASE</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-netflix-core</artifactId>
+        <version>2.0.0.RELEASE</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>pring-cloud-starter-netflix-zuul</artifactId>
+        <version>2.0.0.RELEASE</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
+        <version>2.0.0.RELEASE</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
+        <version>2.0.0.RELEASE</version>
+      </dependency>
 
       <dependency>
         <groupId>org.apache.servicecomb</groupId>
@@ -155,7 +192,6 @@
         <type>pom</type>
         <scope>import</scope>
       </dependency>
-
       <dependency>
         <groupId>org.apache.servicecomb</groupId>
         <artifactId>spring-boot2-starter</artifactId>
@@ -171,7 +207,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 ab0104d..08f9117 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 0000000..3106b16
--- /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 0000000..ad605af
--- /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 0000000..c99befd
--- /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 0000000..3ff1fd3
--- /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 0000000..72f905e
--- /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 0000000..8ab7d36
--- /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 0000000..4592ea9
--- /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 0000000..0feb613
--- /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 0000000..268f112
--- /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