This topic describes how to use Spring Cloud SOFA Registry.
Existing projects
If you have an existing Spring Cloud project that is integrated with a registry center, such as Nacos, Consul, or Eureka, follow the steps in Integrate with Spring Cloud SOFA to complete the common configurations. Then, replace the dependency of the other registry center with the Spring Cloud SOFA Registry dependency.
<!--<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>-->
<dependency>
<groupId>com.alipay.cloud</groupId>
<artifactId>spring-cloud-starter-sofa-registry</artifactId>
</dependency>Spring Cloud SOFA Registry requires a load balancing module. The registry center module does not automatically import one because Spring Cloud SOFA supports multiple versions of Spring Cloud, and each version supports different load balancing modules. Therefore, you must add a dependency for either Ribbon or LoadBalancer to your project.
The following table describes the load balancing modules supported by different Spring Cloud versions:
Version | Ribbon support | LoadBalancer support |
Greenwich | No | Yes (since SR3) |
Hoxton | Yes | Yes |
2020.X | No | Yes |
2021.X | No | Yes |
Example of a manual import:
Add Ribbon
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-ribbon</artifactId> </dependency>Importing a LoadBalancer
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-loadbalancer</artifactId> </dependency>Importing a LoadBalancer (Greenwich version)
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-loadbalancer</artifactId> </dependency>
The Greenwich and Hoxton versions of Spring Cloud support both the Ribbon and LoadBalancer frameworks. Ribbon is the default load balancing framework. To use the LoadBalancer framework in these versions, you must configure it correctly. For more information, see the official Spring Cloud documentation.
No projects
To get started with the SOFA Registry, follow the steps below:
Create a Spring Cloud project and add the dependencies for Spring Cloud SOFA Registry and a load balancer.
NoteDo not specify a version because the version is controlled by dependencyManagement.
<dependency> <groupId>com.alipay.cloud</groupId> <artifactId>spring-cloud-starter-sofa-registry</artifactId> </dependency> <!-- The following example uses LoadBalancer. Select a load balancer based on your Spring Cloud version. --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-loadbalancer</artifactId> </dependency>In the project's startup class, use the
EnableDiscoveryClientannotation to enable service discovery and theEnableFeignClientsannotation to enable OpenFeign.
In the project, use OpenFeign or RestTemplate to call other services.
The following example uses OpenFeign:

In the
application.propertiesfile, setprovider.application.nameto the service name of the provider.
Create another Spring Cloud project to use as the provider test application. Set the application's
spring.application.nametoMySpringCloudProviderApplication. In the startup class, add theEnableDiscoveryClientannotation to enable automatic service registration. Write a Controller to handle requests (details are omitted here).Add the required common configurations, then start the application to test it.
For more information about the required common configurations, see Add common configurations.