This topic describes how to deploy a Spring Boot application to Function Compute. Compared with traditional deployment methods, you can deploy a traditional Spring Boot application to the remote end directly for production with one click. Features such as auto scaling, pay-as-you-go, and maintenance-free are provided.

Background information

Spring Boot was developed by the Pivotal team in 2013 and its first version of the new open-source lightweight framework was released in April 2014. A Spring application is designed based on Spring 4.0. In addition to inheriting excellent features of the Spring Framework, it also simplifies the configuration to further simplify the entire build and development process of Spring applications. In addition, Spring Boot integrates a large number of frameworks to solve problems such as dependency package version conflicts and reference instability.

Step 1: Prepare the environment

You only need to install Funcraft instead of installing Docker. The simplest method is to download the executable binary files.

  1. Install Funcraft on the local machine. For more information, see Install Funcraft.
  2. Run the fun --version command to check whether the installation is successful.

Step 2: Deploy an application

  1. Create a Spring Boot project. For more information, see Spring Quickstart Guide.
  2. Use the following command to enter the sample project you created or an existing project.
    cd <project-name>
  3. Use the following command to run the local project.
    • Runs a project on the MacOS or Linux platform.
      ./mvnw spring-boot:run
    • Run the project on Windows.
      mvnw spring-boot:run
  4. Under the root directory of the project, run the mvn package command for packaging.
    The compiled output is similar to the following example.
    $mvn package
    [INFO] Scanning for projects...
    [INFO] ----------------------< com.example:Spring-Boot >-----------------------
    [INFO] Building Spring-Boot 0.0.1-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ Spring-Boot ---
    ... ... ...
    [INFO] Results:
    [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
    [INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ Spring-Boot ---
    [INFO] Building jar: /Users/txd123/Desktop/Spring-Boot/target/Spring-Boot-0.0.1-SNAPSHOT.jar
    [INFO] --- spring-boot-maven-plugin:2.2.6.RELEASE:repackage (repackage) @ Spring-Boot ---
    [INFO] Replacing main artifact with repackaged archive
    [INFO] ------------------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  38.850 s
    [INFO] Finished at: 2020-03-31T15:09:34+08:00
    [INFO] ------------------------------------------------------------------------
  5. Run the fun deploy -y command to deploy the project to Function Compute.

    Funcraft automatically enters the deployment process.

    $fun deploy -y
    current folder is not a fun project.
    Generating template.yml...
    Generate Fun project successfully!
    ========= Fun will use 'fun deploy' to deploy your application to Function Compute! =========
    using region: cn-qingdao
    using accountId: ***********3743
    using accessKeyId: ***********Ptgk
    using timeout: 60
    Collecting your services information, in order to caculate devlopment changes...
    Resources Changes(Beta version! Only FC resources changes will be displayed):
                   trigger httpTrigger deploy success
           function Spring-Boot deploy success
    service Spring-Boot deploy success
    Detect 'DomainName:Auto' of custom domain 'Domain'
    Request a new temporary domain ...
    The assigned temporary domain is,expired at 2020-04-10 15:19:56, limited by 1000 per day.
    Waiting for custom domain Domain to be deployed...
    custom domain Domain deploy success

    After the deployment is successful, you can see the temporary domain name generated by Function Compute in the log. Through this temporary domain name, you can directly access the just deployed application.

    Note The temporary domain name is only used for demonstration and development and is only valid for a period. For production purposes, bind a domain name that has been filed with Alibaba Cloud.