Spring Cloud Function in Azure
This article outlines the deployment of Spring Cloud Function as a Java Function to Azure Functions, from validation and setup to testing and deployment.
Join the DZone community and get the full member experience.Join For Free
This article covers the usage of Spring Cloud Function as a Java Function and deployment to Azure Functions.
- JDK, version 8+.
- Apache Maven, version 3 or higher.
- Azure Account (free trial would suffice as well).
- Azure CLI.
- Azure Functions Core Tools.
Validating the Local Environment Setup
Verify Apache Maven version:
Verify Azure CLI:
Verify Azure Function Core tools:
Create an empty maven project. Use the below pom.xml and build the project.
Customize below properties in the pom.xml file as per your application.
<functionAppName> — name of your Azure Function
<functionAppRegion> — name of the Azure region where your Function will be deployed
<functionResourceGroup> — name of the Azure resource group which will be used
In the Project base directory create the following configuration files required by the Azure Functions.
Create below Model Classes.
Create the Springboot Application
welcomeEmployee() function returns a
java.util.function.Function and is a Spring bean. It is important that the Azure Functions that we create next will have the same name.
Create the Azure Function
- The Java class which is an Azure Function extends the
AzureSpringBootRequestHandler, does the link between Azure Functions and Spring Cloud Function. This is what provides the
handleRequest()method that is used in its
- The name of the function, defined with
@FunctionName("welcomeEmployee")annotation, is the same as the Spring bean we have configured in the previous step,
Package the application:
Run the project locally:
Below will be the output in the console on successful startup:
Test the setup using Postman:
Deployment to Azure Function
In the command line, run the below command and login to the Azure account.
Deploy to Azure function using below command:
Verify the deployment by logging into the Azure Portal:
Test the Azure function by using Postman:
Opinions expressed by DZone contributors are their own.