You can migrate web projects in Spring Boot by using the custom runtime and HTTP triggers of Function Compute. You can access a function by using a browser or HTTP client tools such as cURL. You can modify the Spring Boot sample code as needed for custom development.

Prerequisites

The following operations are complete:

Procedure

  1. Run the following command to initialize a project:
    s init fc-custom-java8-http -d fc-custom-java8-http
  2. Run the following command to go to the project directory:
    cd fc-custom-java8-http
  3. Optional: Modify the sample code as needed for custom development.
  4. Run the following command to deploy the project:
    s deploy -y
    Sample command output:
    [2022-02-22 09:47:50] [INFO] [S-CLI] - Start the pre-action
    [2022-02-22 09:47:50] [INFO] [S-CLI] - Action: mvn package
    [INFO] Scanning for projects...
    [INFO]
    [INFO] --------------------------< com.example:demo >--------------------------
    [INFO] Building demo 0.0.1-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO]
    [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource
    [INFO] Copying 0 resource
    ......
    [2022-02-22 09:47:50] [INFO] [S-CLI] - Start the pre-action
    [2022-02-22 09:47:50] [INFO] [S-CLI] - Action: mvn package
    [INFO] Scanning for projects...
    [INFO]
    [INFO] --------------------------< com.example:demo >--------------------------
    [INFO] Building demo 0.0.1-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO]
    [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource
    [INFO] Copying 0 resource
    ......
    [INFO] Finished at: 2022-02-22T17:48:17+08:00
    [INFO] ------------------------------------------------------------------------
    [2022-02-22 09:48:17] [INFO] [S-CLI] - End the pre-action
     Checking Service, Function, Triggers (1.46s)
     Creating Service, Function, Triggers (7.09s)
     Creating custom domain (0.1s)
    
    Tips for next step
    ======================
    * Display information of the deployed resource: s info
    * Display metrics: s metrics
    * Display logs: s logs
    * Invoke remote function: s invoke
    * Remove Service: s remove service
    * Remove Function: s remove function
    * Remove Trigger: s remove trigger
    * Remove CustomDomain: s remove domain
    
    helloworld:
      region:   cn-hangzhou
      service:
        name: hello-world-service
      function:
        name:       springbootHttpFunc
        runtime:    custom
        handler:    index.handler
        memorySize: 1024
        timeout:    15
      url:
        system_url:    https://198611443057****.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/hello-world-service/springbootHttpFunc/
        custom_domain:
          -
            domain: http://springboothttpfunc.hello-world-service.198611443057****.cn-hangzhou.fc.devsapp.net
      triggers:
        -
          type: http
          name: httpTrigger

Result

After the project is deployed, you can view the temporary domain name that is generated by Function Compute in the output. The temporary domain name can be used to access the newly deployed application. For example, run the following command to access the application:

curl http://springboothttpfunc.hello-world-service.198611443057****.cn-hangzhou.fc.devsapp.net
Note You can use the temporary domain name only for demonstration and development purposes. It is valid for a limited period of time. In a production environment, you must use a domain name for which an Internet Content Provider (ICP) filing is obtained from Alibaba Cloud. For more information, see Configure a custom domain name.