Author: compose a piece of graceful brush and ink
What is functional computing
Alibaba Cloud Function Compute FC is an event-driven fully managed computing service. With Function Compute, you don't need to procure and manage infrastructure such as servers, you just write and upload code. Function Compute prepares computing resources for you, runs tasks flexibly and reliably, and provides functions such as log query, performance monitoring, and alarming. With Function Compute, you can quickly build any type of applications and services, and only need the actual consumption for tasks payment for resources.
Development steps
Open Function Compute
Before activation, you need to have registered an Alibaba Cloud account and completed real-name authentication, and then enter Function Compute on the official website of Function Compute:
https://fcnext.console.aliyun.com
If you have not yet activated Function Compute, you need to select the Function Compute service agreement on the Function Compute activation page and click "Activate Now". After the activation is completed, you will automatically be redirected to the Function Compute console.
New service
In the Function Compute console, click "Services and Functions" to enter the service list, click Create Service in the service list, fill in the configuration of the service, and click "Confirm" to create the service.
(Note: Enabling the log and link tracking functions can make it easier to debug code, analyze faults, analyze data, and view the time consumption inside functions; it is recommended to enable them, but some fees may be charged).
new function
Click the created service name under the service list to enter the function management page, click "Create function", select "Create with custom runtime" on the function creation page, fill in the relevant configuration of the function, and select the Java 17 sample template function in the runtime environment .
After the configuration is complete, pull down the page to the bottom and click "Create" to deploy a springboot project.
\
Custom Domain Name Configuration
After the function is created, open the request address directly in the browser, and the response will be downloaded as an attachment.
This is because the Http trigger automatically adds the Content-Disposition: attachment field in the response header, we can avoid this problem by using a custom domain name.
Enter the domain name management page and click Add custom domain name, and select the service and function you created in the routing configuration. After the configuration is complete, you can enter the configured domain name in the browser, and you can see the Hello World! content displayed on the page.
At this point, a simple springboot project has been deployed and configured.
develop
export code
Continue to develop the project, we can enter the function details page in the function calculation console, use the online IDE for development and debugging in the function code page, or export the code of the function in "Export function" and use our own code editor for development.
code structure
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
DemoApplication:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
}
Configure listening port
Add the listening port to the application.properties configuration file. The configuration port here needs to be the same as the listening port configured by the function:
Summarize
In this experience, I deployed a springboot project using function computing. Overall, the process is very smooth. You only need to click on the console to generate and deploy a project. It is very friendly to novices and saves a lot of traditional deployment. The environment construction, installation dependencies, etc. during the project can really let us only care about the development of business logic!
Click here for more product information~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。