Quickstart: Build and deploy apps to Azure Spring Apps
Note
Azure Spring Apps is the new name for the Azure Spring Cloud service. Although the service has a new name, you'll see the old name in some places for a while as we work to update assets such as screenshots, videos, and diagrams.
This article applies to: ✔️ Basic/Standard tier ❌ Enterprise tier
In this quickstart, you build and deploy Spring applications to Azure Spring Apps using the Azure CLI.
Prerequisites
Complete the previous quickstarts in this series:
Download the sample app
If you've been using the Azure Cloud Shell up to this point, switch to a local command prompt for the following steps.
Create a new folder and clone the sample app repository.
mkdir source-codecd source-codegit clone https://github.com/Azure-Samples/Azure-Spring-Cloud-SamplesNavigate into the repository directory.
cd Azure-Spring-Cloud-Samples
Deploy PlanetWeatherProvider
Create an app for the PlanetWeatherProvider project in your Azure Spring Apps instance.
az spring app create --name planet-weather-provider --runtime-version NetCore_31To enable automatic service registration, you have given the app the same name as the value of
spring.application.namein the project's appsettings.json file:"spring": { "application": { "name": "planet-weather-provider" } }This command may take several minutes to run.
Change directory to the
PlanetWeatherProviderproject folder.cd steeltoe-sample/src/planet-weather-providerCreate the binaries and the .zip file to be deployed.
dotnet publish -c release -o ./publishTip
The project file contains the following XML to package the binaries in a .zip file after writing them to the ./publish folder:
<Target Name="Publish-Zip" AfterTargets="Publish"> <ZipDirectory SourceDirectory="$(PublishDir)" DestinationFile="$(MSBuildProjectDirectory)/publish-deploy-planet.zip" Overwrite="true" /> </Target>Deploy to Azure.
Make sure that the command prompt is in the project folder before running the following command.
az spring app deploy -n planet-weather-provider --runtime-version NetCore_31 --main-entry Microsoft.Azure.SpringCloud.Sample.PlanetWeatherProvider.dll --artifact-path ./publish-deploy-planet.zipThe
--main-entryoption specifies the relative path from the .zip file's root folder to the .dll file that contains the application's entry point. After the service uploads the .zip file, it extracts all the files and folders and tries to execute the entry point in the specified .dll file.This command may take several minutes to run.
Deploy SolarSystemWeather
Create another app in your Azure Spring Apps instance, this time for the SolarSystemWeather project:
az spring app create --name solar-system-weather --runtime-version NetCore_31solar-system-weatheris the name that is specified in theSolarSystemWeatherproject's appsettings.json file.This command may take several minutes to run.
Change directory to the
SolarSystemWeatherproject.cd ../solar-system-weatherCreate the binaries and .zip file to be deployed.
dotnet publish -c release -o ./publishDeploy to Azure.
az spring app deploy -n solar-system-weather --runtime-version NetCore_31 --main-entry Microsoft.Azure.SpringCloud.Sample.SolarSystemWeather.dll --artifact-path ./publish-deploy-solar.zipThis command may take several minutes to run.
Assign public endpoint
To test the application, send an HTTP GET request to the solar-system-weather application from a browser. To do that, you need a public endpoint for the request.
To assign the endpoint, run the following command.
az spring app update -n solar-system-weather --assign-endpoint trueTo get the URL of the endpoint, run the following command.
Windows:
az spring app show -n solar-system-weather -o tableLinux:
az spring app show --name solar-system-weather | grep url
Test the application
Send a GET request to the solar-system-weather app. In a browser, navigate to the public URL with /weatherforecast appended to the end of it. For example: https://servicename-solar-system-weather.azuremicroservices.io/weatherforecast
The output is JSON:
[{"Key":"Mercury","Value":"very warm"},{"Key":"Venus","Value":"quite unpleasant"},{"Key":"Mars","Value":"very cool"},{"Key":"Saturn","Value":"a little bit sandy"}]
This response shows that both Spring apps are working. The SolarSystemWeather app returns data that it retrieved from the PlanetWeatherProvider app.
This document explains how to build and deploy Spring applications to Azure Spring Apps using:
- Azure CLI
- Maven Plugin
- Intellij
Before deployment using Azure CLI or Maven, complete the examples that provision an instance of Azure Spring Apps and set up the config server. For enterprise tier, please follow set up Application Configuration Service.
Prerequisites
- Install JDK 8 or JDK 11
- Sign up for an Azure subscription
- (Optional) Install the Azure CLI version 2.0.67 or higher and install the Azure Spring Apps extension with command:
az extension add --name spring - (Optional) Install the Azure Toolkit for IntelliJ and sign in
Deployment procedures
Build the Spring applications locally
Clone the sample app repository to your Azure Cloud account. Change the directory, and build the project.
git clone https://github.com/azure-samples/spring-petclinic-microservices cd spring-petclinic-microservices mvn clean package -DskipTests -Denv=cloud
Compiling the project takes 5-10 minutes. Once completed, you should have individual JAR files for each service in their respective folders.
Create and deploy apps on Azure Spring Apps
If you didn't run the following commands in the previous quickstarts, set the CLI defaults.
az configure --defaults group=<resource-group-name> spring=<service-name>Create the 2 core Spring applications for PetClinic: API gateway and customers-service.
az spring app create --name api-gateway --instance-count 1 --memory 2Gi --assign-endpoint az spring app create --name customers-service --instance-count 1 --memory 2GiDeploy the JAR files built in the previous step.
az spring app deploy \ --name api-gateway \ --jar-path spring-petclinic-api-gateway/target/spring-petclinic-api-gateway-2.5.1.jar \ --jvm-options="-Xms2048m -Xmx2048m" az spring app deploy \ --name customers-service \ --jar-path spring-petclinic-customers-service/target/spring-petclinic-customers-service-2.5.1.jar \ --jvm-options="-Xms2048m -Xmx2048m"Query app status after deployments with the following command.
az spring app list --output tableThis command produces output similar to the following example:
Name Location ResourceGroup Production Deployment Public Url Provisioning Status CPU Memory Running Instance Registered Instance Persistent Storage ----------------- ---------- --------------- ----------------------- --------------------------------------------------- --------------------- ----- -------- ------------------ --------------------- -------------------- api-gateway eastus xxxxxx-sp default https://<service name>-api-gateway.azuremicroservices.io Succeeded 1 2 1/1 1/1 - customers-service eastus <service name> default Succeeded 1 2 1/1 1/1 -
Verify the services
Access the app gateway and customers service from browser with the Public Url shown above, in the format of https://<service name>-api-gateway.azuremicroservices.io.

Tip
To troubleshot deployments, you can use the following command to get logs streaming in real time whenever the app is running az spring app logs --name <app name> -f.
Deploy extra apps
To get the PetClinic app functioning with all features like Admin Server, Visits and Veterinarians, you can deploy the other apps with following commands:
az spring app create --name admin-server --instance-count 1 --memory 2Gi --assign-endpoint
az spring app create --name vets-service --instance-count 1 --memory 2Gi
az spring app create --name visits-service --instance-count 1 --memory 2Gi
az spring app deploy --name admin-server --jar-path spring-petclinic-admin-server/target/spring-petclinic-admin-server-2.5.1.jar --jvm-options="-Xms2048m -Xmx2048m"
az spring app deploy --name vets-service --jar-path spring-petclinic-vets-service/target/spring-petclinic-vets-service-2.5.1.jar --jvm-options="-Xms2048m -Xmx2048m"
az spring app deploy --name visits-service --jar-path spring-petclinic-visits-service/target/spring-petclinic-visits-service-2.5.1.jar --jvm-options="-Xms2048m -Xmx2048m"
Clean up resources
If you plan to continue working with subsequent quickstarts and tutorials, you might want to leave these resources in place. When no longer needed, delete the resource group, which deletes the resources in the resource group. To delete the resource group by using Azure CLI, use the following commands:
echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."
Next steps
Maklum balas
Kirim dan lihat maklum balas untuk



