Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
page_type languages products name description
sample
java
azure-cosmos-db
Using Azure Cosmos DB in Spring Boot (MVC On Servlet) Application
This sample demonstrates how to use Azure Cosmos DB in Spring Boot (MVC on servlet stack) application.

Using Azure Cosmos DB in Spring Boot (MVC On Servlet) Application

Image

Features

  • @Query annotation for finder method
  • Collection configuration with annotations(Indexing, RUs).
  • Multiple database and collections accessed from single application.
  • Auto generating UUID based IDs.
  • Spring Data Repository pattern.
  • Enabling cosmos request diagnostics
  • Directly using CosmosAsynClient from a spring application.
  • Infinite scroll with JQuery.
  • Filter by category.

Getting started

Pre-requisites

  • Java Development Kit 8.
  • An active Azure account. If you don't have one, you can sign up for a free account. Alternatively, you can use the Azure Cosmos DB Emulator for development and testing. As emulator https certificate is self-signed, you need to import its certificate to java trusted cert store, explained here.
  • Maven.
  • (Optional) SLF4J is a logging facade.
  • (Optional) SLF4J binding is used to associate a specific logging framework with SLF4J.

Installation

  1. Clone this repo and change working directory:
    git clone https://github.com/Azure-Samples/azure-spring-boot-samples.git
    cd cosmos/azure-spring-data-cosmos/cosmos-mvc-sample
  2. Add the azure.cosmos.bookstore.uri and azure.cosmos.bookstore.key in application.yaml.
  3. Compile and run:
    mvn spring-boot:run
  4. On startup the application creates 2 databases, with 3 collections in the "store" database, and one collection in the "security" database.
  5. Access the WebApp at http://localhost:81/ebooks/index
  6. You will have to create user account to access the application functionality. The registration process asks for email ID, which will be used as the login ID. Any email address is fine as long as it has a valid format.

Deploy to Azure Spring Apps

Now that you have the Spring Boot application running locally, it's time to move it to production. Azure Spring Apps makes it easy to deploy Spring Boot applications to Azure without any code changes. The service manages the infrastructure of Spring applications so developers can focus on their code. Azure Spring Apps provides lifecycle management using comprehensive monitoring and diagnostics, configuration management, service discovery, CI/CD integration, blue-green deployments, and more. To deploy your application to Azure Spring Apps, see Deploy your first application to Azure Spring Apps.