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 Cosmos DB backend, Azure Redis Cache and using Key Vault for storing secrets
- Open the application
- An Azure subscription
- Terraform
- JDK8 or later
- MySQL CLI
- Git
- Jq
- Docker
- Maven
- You can also import the code straight into your IDE:
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.
Terraform must authenticate to Azure to create infrastructure.
In your terminal, use the Azure CLI tool to setup your account permissions locally.
az login
Your browser window will open and you will be prompted to enter your Azure login credentials. After successful authentication, your terminal will display your subscription information. You do not need to save this output as it is saved in your system for Terraform to use.
You have logged in. Now let us find all the subscriptions to which you have access...
[
{
"cloudName": "AzureCloud",
"homeTenantId": "home-Tenant-Id",
"id": "subscription-id",
"isDefault": true,
"managedByTenants": [],
"name": "Subscription-Name",
"state": "Enabled",
"tenantId": "0envbwi39-TenantId",
"user": {
"name": "[email protected]",
"type": "user"
}
}
]
If you have more than one subscription, specify the subscription-id you want to use with command below:
az account set --subscription <your-subscription-id>
After login Azure CLI with your account, now you can use the terraform script to create Azure Resources.
# In the root directory of the sample
# Initialize your Terraform configuration
terraform -chdir=./terraform init
# Apply your Terraform Configuration
terraform -chdir=./terraform apply -auto-approve
# In the root directory of the sample
# Initialize your Terraform configuration
terraform -chdir=terraform init
# Apply your Terraform Configuration
terraform -chdir=terraform apply -auto-approve
It may take a few minutes to run the script. After successful running, you will see prompt information like below:
azurerm_resource_group.main: Creating...
azurerm_key_vault.kv_account: Creating...
azurerm_redis_cache.redis: Creating...
azurerm_cosmosdb_account.application: Creating...
azurerm_redis_cache.redis: Still creating...
azurerm_key_vault.kv_account: Still creating...
azurerm_cosmosdb_account.application: Still creating...
...
azurerm_cosmosdb_account.application: Still creating...
azurerm_redis_cache.redis: Still creating...
azurerm_key_vault.kv_account: Still creating...
azurerm_key_vault.kv_account: Still creating...
azurerm_redis_cache.redis: Still creating...
...
Apply complete! Resources: 8 added, 0 changed, 0 destroyed.
Outputs:
...
You can go to Azure portal in your web browser to check the resources you created.
Running the command below to export environment values:
source ./terraform/setup_env.sh
Running the command below to export environment values:
terraform\setup_env.ps1
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 command below from a project root:
mvn clean install -P buildDocker -DskipTests
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
.
After running the sample, if you don't want to run the sample, remember to destroy the Azure resources you created to avoid unnecessary billing.
The terraform destroy command terminates resources managed by your Terraform project.
To destroy the resources you created.
az group delete --name $(terraform -chdir=./terraform output -raw resource_group_name) --yes
az group delete --name $(terraform -chdir=terraform output -raw resource_group_name) --yes
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 Cosmos DB
The application could be reached at http://localhost:8080
To secure the Java applications in this sample please follow the Spring Security Microsoft Entra ID tutorial . After setting your Active directory you can enable security on Customers service by uncommenting the relevant Microsoft Entra ID 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
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 [email protected] with any additional questions or comments.