page_type | languages | products | name | description | ||
---|---|---|---|---|---|---|
sample |
|
|
Using Azure Cosmos DB By Spring Data in Spring Boot Application |
This sample demonstrates how to use Azure Cosmos DB in Spring Boot application. |
- This sample only work with Spring Boot 3 Azure Spring Data Azure Cosmos DB Quickstart sample project.
Basic sample code for getting started with azure-spring-data-cosmos for Azure Cosmos DB SQL API.
Java Development Kit 8
or higher.- 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. SLF4J is only needed if you plan to use logging, please also download an SLF4J binding which will link the SLF4J API with the logging implementation of your choice. See the SLF4J user manual for more information.
- git clone https://github.com/Azure-Samples/azure-spring-boot-samples.git
- cd cosmos/azure-spring-data-cosmos/cosmos-quickstart-samples
- Add environment variables
ACCOUNT_HOST
andACCOUNT_KEY
with Cosmos DB uri and primary key respectively (seeresources/application.yaml
). - mvn spring-boot:run
Please refer to azure spring data cosmos for sql api azure-spring-data-cosmos source code for more information.
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.