Skip to content

Latest commit

 

History

History
 
 

spring-petclinic-microservices

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Error in user YAML: (<unknown>): did not find expected key while parsing a block mapping at line 1 column 1
---
page_type: sample
languages:
- java
products:
- Azure Spring Integration Starters 
description: "Deploy Spring microservices using Spring Integration starters for Azure"
  urlFragment: "spring-petclinic-microservices"

---

Deploy Spring Microservices using Azure Spring starters for Cosmos DB, Redis, KeyVault

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.

What will you experience

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

What you will need

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 |

Clone and build the repo

Create a new folder and clone the sample app repository to your Azure Cloud account

    mkdir source-code
    git clone https://github.com/Azure-Samples/azure-spring-boot-samples

Change directory and build the project

    cd azure-spring-boot-samples/spring-petclinic-microservices
    mvn clean package -DskipTests

This will take a few minutes.

Provision Azure resources using Azure CLI

Login to Azure

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}

Prepare your environment for deployments

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.

Starting services locally with docker-compose

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.

Understanding the Spring Petclinic application

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/

Spring Petclinic Microservices screenshot

Architecture diagram of the Spring Petclinic Microservices with CosmosDB

Spring Petclinic Microservices architecture

Navigate to the application

The application could be reached at http://localhost:8080

Enabling Spring boot starter for Azure Active directory (Optional)

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.

Next Steps

In this quickstart, you've deployed an existing Spring microservices app using Azure CLI. To learn more about Spring on Azure, go to:

Credits

This Spring microservices sample is forked from spring-petclinic/spring-petclinic-microservices

Contributing

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.