All Products
Search
Document Center

Serverless App Engine:Smoothly migrate Spring Cloud applications to SAE

Last Updated:Mar 20, 2025

If your Spring Cloud cluster that contains multiple applications is deployed on Alibaba Cloud, you can migrate the applications to Serverless App Engine (SAE). This topic describes how to smoothly migrate applications to SAE and perform service registration and discovery.

Migration process

迁移流程

  1. Required: Migrate an application

    In most cases, an application to be migrated is stateless and must be migrated first.

  2. Optional: Migrate a Server Load Balancer (SLB) instance or modify the domain name settings

    After the application is migrated, you must migrate the SLB instance that is bound to the application or modify the domain name settings.

    • SLB instance

      • If an SLB instance is used before migration, you can reuse the SLB instance after migration. You can select a policy to bind the SLB instance to your application based on your business requirements. For more information, see Bind an SLB instance to an application.

      • If no SLB instance is used before migration, we recommend that you create an SLB instance and bind it to the ingress application such as an API gateway after migration, as shown in the preceding figure.

      • When you migrate an application, we recommend that you enable dual-registration and dual-subscription to reduce the costs of using Elastic Compute Service (ECS). If an existing ECS instance cannot be used due to specific causes (for example, the original port configured for the ECS instance is occupied), you must use the traffic-splitting migration solution and add new ECS instances. After the application is migrated, reuse the existing SLB instance or create an SLB instance and bind it to the migrated application based on your business requirements.

    • Domain name

      • If an SLB instance can be reused after migration, you do not need to modify the domain name.

      • If you want to create an SLB instance and bind it to the migrated application, you must add a new SLB instance to the domain name settings and delete the SLB instance that is no longer required. For more information, see Change DNS servers for a domain name.

  3. Optional: Migrate storage and message queues

    • If your application is deployed on Alibaba Cloud and uses Alibaba Cloud services, such as ApsaraDB RDS and Message Queue, you do not need to migrate storage or message queues.

    • If your application is not deployed on Alibaba Cloud, join the DingTalk group (ID: 32874633) to obtain technical support.

This topic provides an example on how to smoothly migrate a demo application to SAE. For information about the download URL of the demo application, see Demo.

Migration solutions

You can use one of the following solutions to migrate applications: traffic-splitting, and dual-registration and dual-subscription. Both solutions ensure smooth application migration without business interruption.

Note

This section describes the dual-registration and dual-subscription migration solution.

  • Traffic-splitting

    Use Spring Cloud Alibaba to switch the original service registry to Nacos, develop a new set of applications, and then deploy the applications on SAE. Then, use SLB and configure domain names to switch traffic.

    For more information, see Host Spring Cloud applications to SAE.

  • Dual-registration and dual-subscription

    The dual-registration and dual-subscription solution refers to access the original service registry and the SAE service registry during migration. This ensures that migrated applications and non-migrated applications call each other.

    The following figure shows the architecture of the dual-registration and dual-subscription migration solution.

    Initial status

    image

    Step 1

    image

    Step 2

    image

    Step 3

    image

    Step 4

    image
    • Migrated applications and non-migrated applications can discover and call each other. This ensures business continuity.

    • You need only to add dependencies and modify a small amount of code to implement dual-registration and dual-subscription.

    • You can view the details of consumer service calls and view the migration progress in real time.

    • You can dynamically modify the policies of service registration and subscription without the need to repeatedly restart applications. You need to restart applications only once in the migration process.

Step 1: Migrate the first application

  1. Assign the priority of the application that you want to migrate to SAE.

    Select an application with a high priority for migration. We recommend that you start migration from underlying providers. You can randomly select an application to be migrated if the trace is complex and difficult to analyze.

  2. Add dependencies to the application and modify its configuration.

    1. Add the spring-cloud-starter-alibaba-nacos-discovery dependency to the pom.xml file.

      <dependency>
           <groupId>org.springframework.cloud</groupId>
           <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
           <version>{Version}</version>
       </dependency>
    2. Add the IP address of Nacos Server to application.properties.

      spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848                            
    3. Add the edas-sc-migration-starter dependency for multiple registries.

      By default, Spring Cloud allows you to add only one registry as a dependency to the pom.xml file. If you attempt to add multiple registries, an error is returned. To support multiple registries in Spring Cloud, add the edas-sc-migration-starter dependency.

      <dependency>
           <groupId>com.alibaba.edas</groupId>
           <artifactId>edas-sc-migration-starter</artifactId>
           <version>1.0.2</version>
       </dependency>                            
  3. Modify the default configurations of RibbonClients.

    To allow an application to subscribe to services from multiple registries, you must modify the configurations of Ribbon that is used for load balancing. In the main class of application startup, set RibbonClients to MigrationRibbonConfiguration.

    The following code is the original main class code:

    @SpringBootApplication
     public class ConsumerApplication {
         public static void main(String[] args) {
             SpringApplication.run(ConsumerApplication.class, args);
         }
     }                                

    The following code is the modified main class code:

    @SpringBootApplication
     @RibbonClients(defaultConfiguration = MigrationRibbonConfiguration.class)
     public class ConsumerApplication {
         public static void main(String[] args) {
             SpringApplication.run(ConsumerApplication.class, args);
         }
     }                                
    Note

    After applications are modified in your on-premises machine or deployed on SAE, you can manage the applications. For example, you can register the applications with specific registries or subscribe to services from specific registries. To meet the requirements, use Spring Cloud Config or Nacos Config to dynamically adjust the configurations of the applications. In this case, you do not need to restart applications. For more information, see Dynamically adjust service registration policies and service subscription policies.

    To use Spring Cloud Config or Nacos Config, you must add the configuration management dependency to the applications and modify related configurations. If you use Spring Cloud Config, refer to open source documentation. If you use Nacos Config, refer to Manage application configurations.

  4. Deploy the application on SAE.

    Deploy the application on SAE based on your business requirements. For more information, see Application deployment.

  5. Use one of the following methods to verify the result.

    1. Check whether your business runs as expected.

    2. View the monitoring data of service subscription.

      • Spring Boot 1.x: http://ip:port/dubboRegistry

      • Spring Boot 2.x: http://ip:port/actuator/dubboRegistry

      If Spring Boot Actuator is enabled for the application, you can access Actuator to view the RibbonServerList information of each service to which the application subscribes. The following figure shows the URL that you can use to access Actuator. The serverGroup field in metaInfo indicates the service registry for the node.

      开启Spring Boot Actuator监控

Step 2: Migrate other applications

Migrate all applications to SAE in sequence. For more information, see Step 1: Migrate the first application.

Step 3: Delete migration configurations

After migration, delete the original service registry configurations and the edas-sc-migration-starter dependency that is used during migration.

edas-sc-migration-starter is a dedicated starter for migration. If you use the starter for a long period of time, the starter does not affect service stability, but limits the load balancing effect of Ribbon. We recommend that you delete the starter after migration and restart applications in batches during off-peak hours.

  • Dynamically adjust service registration policies and service subscription policies

    You can use the configuration management feature of SAE to dynamically adjust service registration policies and service subscription policies during migration.

  • Dynamically adjust the service subscription policy

    The default subscription policy allowing SAE to subscribe to and aggregate service data from all related registries.

    To subscribe to data from specific registries, you can use the configuration management feature of SAE to modify the spring.cloud.edas.migration.subscribes property.

    spring.cloud.edas.migration.subscribes=nacos,eureka # Subscribes to services from Eureka and Nacos. 
    spring.cloud.edas.migration.subscribes=nacos         # Subscribe to services only from Nacos.                         
  • Dynamically adjust the service registration policy

    The default registration policy allowing SAE to register with all related registries.

    You can use the configuration management feature of SAE to adjust service registries.

    Use the spring.cloud.edas.migration.registry.excludes property to specify the registry that you want to disable.

    spring.cloud.edas.migration.registry.excludes=   # By default, the value is empty. This indicates registration with all service registries. 
    spring.cloud.edas.migration.registry.excludes=eureka        # Disable registration with Eureka. 
    spring.cloud.edas.migration.registry.excludes=nacos,eureka  # Disable registration with Nacos and Eureka.                        

    In this example, if you need to dynamically modify the registries with which an application is registered when the application is running, you can use the configuration management feature of Spring Cloud to modify the property.