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.

Prerequisites

Before you begin, make sure that the following operations are complete:
  • Install Node.js 8.6.0 or later. For more information, visit Downloads.

Procedure

  1. Run the following command to clone the sample project to the on-premises machine:
    git clone https://github.com/awesome-fc/fc-custom-demo          
    Note If you do not install Git, you can download the sample project from https://github.com/awesome-fc/fc-custom-demo.
  2. Optional:Modify the sample code in the spring-boot-demo directory to implement your business logic.
  3. Run the following command to go to the cloned sample project:
    1. Run the following command to go to the fc-custom-demo directory:
      cd fc-custom-demo
    2. Run the following command to go to the spring-boot-demo directory:
      cd spring-boot-demo
  4. Run the following command to install dependencies:
    ./mvnw package
    The following output is returned:
    [INFO] Scanning for projects...
    [INFO] 
    [INFO] --------------------------< com.example:demo >--------------------------
    [INFO] Building demo 0.0.1-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    ...
    [INFO]  T E S T S
    ...
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  25.332 s
    [INFO] Finished at: 2021-03-25T14:56:29+08:00
    [INFO] ------------------------------------------------------------------------
  5. Run the following command to deploy the project to Function Compute:
    fun deploy -y
    The following output is returned:
    ...
    Waiting for service springboot to be deployed...
            Waiting for function helloworld to be deployed...
                    Waiting for packaging function helloworld code...
                    The function helloworld has been packaged. A total of 3 files were compressed and the final size was 14.33 MB
                    Waiting for HTTP trigger httpTrigger to be deployed...
                    triggerName: httpTrigger
                    methods: [ 'GET', 'POST', 'PUT' ]
                    trigger httpTrigger deploy success
            function helloworld deploy success
    service springboot deploy success
    
    Detect 'DomainName:Auto' of custom domain 'my_domain'
    Request a new temporary domain ...
    The assigned temporary domain is http://********-*********.test.functioncompute.com, expired at 2021-04-04 15:09:44, limited by 1000 per day.
    Waiting for custom domain my_domain to be deployed...
    custom domain my_domain deploy success
  6. Run the following command to invoke the deployed function:
    curl http://********-*********.test.functioncompute.com
    Notice
    • http://********-*********.test.functioncompute.com can be obtained from the output of Step 5.
    • If you use the Windows operating system, you must convert the format of the bootstrap file to UNIX.
    The following output is returned:
    Hello, World!