Skip to content

Files

Latest commit

d098597 · Oct 23, 2019

History

History
This branch is 5 commits ahead of, 35 commits behind microsoft/azure-spring-boot:master.

azure-cosmosdb-spring-boot-sample

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Oct 23, 2019
Sep 30, 2019
Aug 20, 2019
Oct 23, 2019

Overview

This sample project demonstrates how to use Azure CosmosDB via Spring Boot Starter azure-cosmosdb-spring-boot-starter to store data in and retrieve data from your Azure Cosmos DB.

Prerequisites

Quick Start

Create an Azure Cosmos DB on Azure

  1. Go to Azure portal and click +New .
  2. Click Databases, and then click Azure Cosmos DB to create your database.
  3. Navigate to the database you have created, and click Access keys and copy your URI and access keys for your database.

Config the sample

  1. Navigate to src/main/resources and open application.properties.
  2. replace below properties in application.properties with information of your database.
    azure.cosmosdb.uri=your-cosmosdb-uri
    azure.cosmosdb.key=your-cosmosdb-key
    azure.cosmosdb.database=your-cosmosdb-databasename

Run the sample

  1. Change directory to folder azure-cosmosdb-spring-boot-sample.

  2. Run below commands.

    • Use Maven

      mvn package
      java -jar target/azure-ducumentdb-spring-boot-sample-0.0.1-SNAPSHOT.jar
      
    • Use Gradle

      gradle bootRepackage
      java -jar build/libs/azure-ducumentdb-spring-boot-sample-0.0.1-SNAPSHOT.jar
      

Known issue

Directly running the sample app from IDE IntelliJ or Eclipse has below security exception if using the released starter. The root cause is that the release spring-data-azure-cosmosdb jar is code-signed by us. We're working actively to resolve this issue.

Caused by: java.lang.SecurityException: class "com.microsoft.azure.sample.User_Accessor_yhb3bq"'s signer information does not match signer information of other classes in the same package
	at java.lang.ClassLoader.checkCerts(ClassLoader.java:898) ~[na:1.8.0_131]
	at java.lang.ClassLoader.preDefineClass(ClassLoader.java:668) ~[na:1.8.0_131]
	at java.lang.ClassLoader.defineClass(ClassLoader.java:761) ~[na:1.8.0_131]

If com.fasterxml.jackson.databind.JsonMappingException is thrown during deserialization, with error message Can not construct instance of {your.pojo.class}: no suitable constructor found, can not deserialize from Object value (missing default constructor..., add Lombok annotatations @Data and @AllArgsConstructor for your POJO class, or use Jackson annotations @JsonCreator and @JsonProperty for the full argument constructor.

More details

Please refer to this article for the tutorial about how to use the Spring Boot Starter with Azure Cosmos DB API.