What should be the datasource configuration for cosmosdb in springboot project to use JdbcTemplate

Author: Sakshi Kumari

I have provided the azure.cosmosdb.uri, azure.cosmosdb.key and azure.cosmosdb.database definition in my application.properties file.

When I am using DocumentDbRepository, I am able to perform CRUD operations to my cosmos db.

I want to use JDBC template for my project to write customize queries using JDBCTemplate.queryForString() methods. I autowired the JDBCTemplate class in my DAO class:

But still I am getting the below error:


APPLICATION FAILED TO START


Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

DAO class code-

package com.walmart.Ods;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;
import java.util.Map;

public class TechDAO{

   public void select(String id)
   {
       String queryString = "SELECT * FROM [DATABASE_NAME] g WHERE g.id = ? ";

       @Autowired
       private JdbcTemplate jdbcTemplate;

        List<Map<String, Object>> result = 
   getJdbcTemplate().queryForList(queryString, new Object[]{id});

  }

}

application.properties file -

azure.cosmosdb.uri=***

azure.cosmosdb.key=***

azure.cosmosdb.database=***

pom.xml file -

https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.8.RELEASE com.walmart Ods 0.0.1-SNAPSHOT Ods Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
    <azure.version>2.1.7</azure.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-cosmosdb-spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-spring-boot-bom</artifactId>
            <version>${azure.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Originally Sourced from: https://stackoverflow.com/questions/57901302/what-should-be-the-datasource-configuration-for-cosmosdb-in-springboot-project-t