---
page_type: sample
languages:
- java
products:
- Azure Spring Integration Starters
description: "Deploy Spring microservices using Spring Integration starters for Azure"
urlFragment: "spring-petclinic-microservices"
---
Azure Spring Cloud enables you to easily run a Spring Boot based microservices application on Azure.
This quickstart shows you how to deploy an existing Java Spring Cloud application to Azure. When you're finished, you can continue to manage the application via the Azure CLI or switch to using the Azure portal.
You will:
- Build existing Spring microservices applications
- Provision azure resources required for the application
- Run the application locally with CosmosDB backend, Azure Redis Cache and using KeyVault for storing secrets
- Open the application
In order to deploy a Java app to cloud, you need an Azure subscription. If you do not already have an Azure subscription, you can activate your MSDN subscriber benefits or sign up for a free Azure account.
In addition, you will need the following:
| Azure CLI version 2.0.67 or higher | Java 8 | Maven | MySQL CLI | Git | Jq |
mkdir source-code
git clone https://github.com/Azure-Samples/azure-spring-boot-samples
cd azure-spring-boot-samples/spring-petclinic-microservices
mvn clean package -DskipTests
This will take a few minutes.
Login to the Azure CLI and choose your active subscription. Be sure to choose the active subscription that is whitelisted for Azure Spring Cloud
az login
az account list -o table
az account set --subscription ${SUBSCRIPTION}
Create a bash script with environment variables by making a copy of the supplied template:
cp .scripts/setup-env-variables-azure-template.sh .scripts/setup-env-variables-azure.sh
Open .scripts/setup-env-variables-azure.sh
and enter the following information:
export SUBSCRIPTION=subscription-id # customize this
export RESOURCE_GROUP=resource-group-name # customize this
export LOCATION=SouthCentralUS #customize this
export COSMOSDB_NAME=mycosmosdbaccname # customize this
export REDIS_NAME=myredisname #customize this
export KEYVAULT_NAME=myend2endkv #customize this
export APP_NAME_FOR_KEYVAULT=myappforkeyvault #customize this
Then, set the environment:
source .scripts/setup-env-variables-azure.sh
make sure keyvault.env file is created at the root of the repo.
In order to start entire infrastructure using Docker, you have to build images by
executing ./mvnw clean install -P buildDocker -DskipTests
from a project root. Once images are ready, you can start them with a single command
docker-compose up
. Containers startup order is coordinated
with dockerize
script. After starting services it takes a
while for API Gateway to be in sync with service registry, so don't be scared of initial Spring
Cloud Gateway timeouts. You can track services availability using Eureka dashboard available by
default at http://localhost:8761.
See the presentation of the Spring Petclinic Framework version
A blog bost introducing the Spring Petclinic Microsevices ( french language)
You can then access petclinic here: http://localhost:8080/
Architecture diagram of the Spring Petclinic Microservices with CosmosDB
The application could be reached at http://localhost:8080
To secure the Java applications in this sample please follow the Spring Security Azure Active Directory tutorial . After setting your Active directory you can enable security on Customers service by uncommenting the relevant AAD sample code.
In this quickstart, you've deployed an existing Spring microservices app using Azure CLI. To learn more about Spring on Azure, go to:
This Spring microservices sample is forked from spring-petclinic/spring-petclinic-microservices
- see Petclinic README.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.