Bind an Azure Cosmos DB database to your Azure Spring Cloud application

This article applies to: ✔️ Java

Instead of manually configuring your Spring Boot applications, you can automatically bind select Azure services to your applications by using Azure Spring Cloud. This article demonstrates how to bind your application to an Azure Cosmos DB database.


Prepare your Java project

  1. Add one of the following dependencies to your Azure Spring Cloud application's pom.xml file. Choose the dependency that is appropriate for your API type.

    • API type: Core (SQL)

    • API type: MongoDB

    • API type: Cassandra

    • API type: Azure Table

  2. Update the current app by running az spring-cloud app deploy, or create a new deployment for this change by running az spring-cloud app deployment create.

Bind your app to the Azure Cosmos DB

Azure Cosmos DB has five different API types that support binding. The following procedure shows how to use them:

  1. Create an Azure Cosmos DB database. Refer to the quickstart on creating a database for help.

  2. Record the name of your database. For this procedure, the database name is testdb.

  3. Go to your Azure Spring Cloud service page in the Azure portal. Go to Application Dashboard and select the application to bind to Azure Cosmos DB. This application is the same one you updated or deployed in the previous step.

  4. Select Service binding, and select Create service binding. To fill out the form, select:

    • The Binding type value Azure Cosmos DB.
    • The API type.
    • Your database name.
    • The Azure Cosmos DB account.


    If you are using Cassandra, use a key space for the database name.

  5. Restart the application by selecting Restart on the application page.

  6. To ensure the service is bound correctly, select the binding name and verify its details. The property field should be similar to this example:

    azure.cosmosdb.uri=https://<some account>

Next steps

In this article, you learned how to bind your Azure Spring Cloud application to an Azure Cosmos DB database. To learn more about binding services to your application, see Bind to an Azure Cache for Redis cache.