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 explains how to build and deploy Spring applications to Azure Spring Apps. You can use Azure CLI, the Maven plugin, or Intellij. This article describes each alternative.
Build the Spring applications locally
Use the following commands to clone the sample repository, navigate to the sample folder, and then 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. When the project is compiled, you should have individual JAR files for each service in their respective folders.
Create and deploy apps on Azure Spring Apps
Use the following steps to create and deploys apps on Azure Spring Apps using the CLI.
If you didn't run the following commands in the previous quickstarts, run them now to set the CLI defaults.
az configure --defaults group=<resource-group-name> spring=<service-name>
Create the two core Spring applications for PetClinic: api-gateway
and customers-service
.
az spring app create \
--name api-gateway \
--runtime-version Java_17 \
--instance-count 1 \
--memory 2Gi \
--assign-endpoint
az spring app create \
--name customers-service \
--runtime-version Java_17 \
--instance-count 1 \
--memory 2Gi
Deploy the JAR files built in the previous step.
az spring app deploy \
--name api-gateway \
--artifact-path spring-petclinic-api-gateway/target/api-gateway-3.0.1.jar \
--jvm-options="-Xms2048m -Xmx2048m"
az spring app deploy \
--name customers-service \
--artifact-path spring-petclinic-customers-service/target/customers-service-3.0.1.jar \
--jvm-options="-Xms2048m -Xmx2048m"
Query the app status after deployments with the following command.
az spring app list --output table
This 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 chinanorth2 xxxxxx-sp default https://<service name>-api-gateway.microservices.azure.cn Succeeded 1 2 1/1 1/1 -
customers-service chinanorth2 <service name> default Succeeded 1 2 1/1 1/1 -
Verify the services
Access api-gateway
and customers-service
from a browser with the Public Url shown previously, in the format of https://<service name>-api-gateway.microservices.azure.cn
.
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> --follow
.
To get the PetClinic app functioning with all features like Admin Server, Visits, and Veterinarians, deploy the other apps with following commands:
az spring app create \
--name admin-server \
--runtime-version Java_17 \
--instance-count 1 \
--memory 2Gi \
--assign-endpoint
az spring app create \
--name vets-service \
--runtime-version Java_17 \
--instance-count 1 \
--memory 2Gi
az spring app create \
--name visits-service \
--runtime-version Java_17 \
--instance-count 1 \
--memory 2Gi
az spring app deploy \
--name admin-server \
--runtime-version Java_17 \
--artifact-path spring-petclinic-admin-server/target/admin-server-3.0.1.jar \
--jvm-options="-Xms1536m -Xmx1536m"
az spring app deploy \
--name vets-service \
--runtime-version Java_17 \
--artifact-path spring-petclinic-vets-service/target/vets-service-3.0.1.jar \
--jvm-options="-Xms1536m -Xmx1536m"
az spring app deploy \
--name visits-service \
--runtime-version Java_17 \
--artifact-path spring-petclinic-visits-service/target/visits-service-3.0.1.jar \
--jvm-options="-Xms1536m -Xmx1536m"
Build the Spring applications locally
Use the following commands to clone the sample repository, navigate to the sample folder, and then 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. When the project is compiled, you should have individual JAR files for each service in their respective folders.
Generate configurations and deploy to Azure Spring Apps
The following steps show you how to generate configurations and deploy to Azure Spring Apps:
Go to the spring-petclinic-customers-service folder. Generate configurations by running the following command. If you've already signed-in with Azure CLI, the command automatically picks up the credentials. Otherwise, it signs you in using a prompt with instructions. For more information, see Authentication on the azure-maven-plugins wiki.
mvn com.microsoft.azure:azure-spring-apps-maven-plugin:1.17.0:config -DappName=customers-service
You're asked to provide the following values:
- Subscription: The subscription you used to create an Azure Spring Apps instance.
- Service Instance: The name of your Azure Spring Apps instance.
- Public endpoint: Whether to assign a public endpoint to the app. Select No.
Verify that the appName
elements in the POM files are correct:
<build>
<plugins>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-spring-apps-maven-plugin</artifactId>
<version>1.17.0</version>
<configuration>
<subscriptionId>xxxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx</subscriptionId>
<clusterName>v-spr-cld</clusterName>
<appName>customers-service</appName>
The POM now contains the plugin dependencies and configurations.
Deploy the apps by using the following command:
mvn azure-spring-apps:deploy
Go to the spring-petclinic-api-gateway folder. Run the following commands to generate the configuration and deploy api-gateway
. Select yes for Public endpoint.
mvn com.microsoft.azure:azure-spring-apps-maven-plugin:1.17.0:config -DappName=api-gateway
mvn azure-spring-apps:deploy
Verify the services
A successful deployment command returns a URL in the form: https://<service name>-spring-petclinic-api-gateway.microservices.azure.cn
. Use it to navigate to the running service.
You can also navigate the Azure portal to find the URL.
- Navigate to the service.
- Select Apps.
- Select api-gateway.
- Find the URL on the api-gateway | Overview page.
To get the PetClinic app functioning with all sections like Admin Server, Visits, and Veterinarians, you can deploy the other Spring applications. Rerun the configuration command and select the following applications.
- admin-server
- vets-service
- visits-service
Correct the app names in each pom.xml file for these modules, and then run the deploy
command again.
Import sample project in IntelliJ
Use the following steps to import the sample project in IntelliJ.
Download and unzip the source repository for this tutorial, or clone it using Git: git clone https://github.com/azure-samples/spring-petclinic-microservices
Open the IntelliJ Welcome dialog and select Import Project to open the import wizard.
Select the spring-petclinic-microservices folder.
Deploy the api-gateway app to Azure Spring Apps
To deploy to Azure, you must sign in with your Azure account with Azure Toolkit for IntelliJ and choose your subscription. For sign-in details, see Create a Hello World web app for Azure App Service using IntelliJ.
Right-click your project in IntelliJ project explorer, and select Azure -> Deploy to Azure Spring Apps.
In the Name field, append :api-gateway to the existing Name.
In the Artifact textbox, select spring-petclinic-api-gateway-3.0.1.
In the Subscription textbox, verify your subscription.
In the Spring Apps textbox, select the instance of Azure Spring Apps that you created in Provision Azure Spring Apps instance.
In the App: textbox, select Create app....
Enter api-gateway, then select OK.
Set Public Endpoint to Enable.
Set Memory to 2.0Gi
and JVM options to -Xms2048m -Xmx2048m
.
In the Before launch section of the dialog, double-click Run Maven Goal.
In the Working directory textbox, navigate to the spring-petclinic-microservices/spring-petclinic-api-gateway folder.
In the Command line textbox, enter package -DskipTests. Select OK.
Start the deployment by selecting the Run button at the bottom of the Deploy Azure Spring Apps app dialog. The plug-in runs the command mvn package
on the api-gateway
app and deploys the JAR file generated by the package
command.
Deploy customers-service and other apps to Azure Spring Apps
Repeat the previous steps to deploy customers-service
and other Pet Clinic apps to Azure Spring Apps:
- Modify the Name and Artifact to identify the
customers-service
app.
- In the App: textbox, select Create app... to create
customers-service
app.
- Verify that the Public Endpoint option is set to Disabled.
- In the Before launch section of the dialog, switch the Working directory to the petclinic/customers-service folder.
- Start the deployment by selecting the Run button at the bottom of the Deploy Azure Spring Apps app dialog.
Verify the services
Navigate to the URL of the form: https://<service name>-spring-petclinic-api-gateway.microservices.azure.cn
You can also navigate the Azure portal to find the URL.
- Navigate to the service
- Select Apps
- Select api-gateway
- Find the URL on the api-gateway | Overview page
Other Spring applications included in this sample can be deployed similarly.
- admin-server
- vets-service
- visits-service
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