Spring MVC with Azure Cosmos DB - sample
Sample e-commerce application built with Spring Boot (MVC on servlet stack) and "Spring Data Cosmos" client library for Azure Cosmos DB SQL API.
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.
- Clone the repo.
Installation
- Update the cosmos DB endpoint, key and locations information in application.properties
- mvn spring-boot:run from the project base
- On startup the application creates 2 databases and 4 collections between them.
- Access the WebApp at http://localhost:81/ebooks/index
- 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.
- If you prefer docker:
- mvn package
- docker build -t /ebookstorespringbootmvc .
- docker run -p 80:80 -e azure.cosmos.bookstore.uri=<COSMOS_ENDPOINT> -e azure.cosmos.bookstore.key=<COSMOS_KEY> -t /ebookstorespringbootmvc
- Access the WebApp at http://localhost:81/ebooks/index