I am trying to connect Azure Cosmos and trying to retrieve data but falling due to below issue(compile time).
=========== Start 1.POM.xml ======================
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.beginsecure</groupId>
<artifactId>CosmosUtility</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-sdk-bom</artifactId>
<version>1.2.23</version>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.12.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-cosmos</artifactId>
<version>4.58.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.32</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20240303</version>
</dependency>
</dependencies>
</project>
=========== End 1.POM.xml ======================
=========== Start 2.CosmosHelper.java ====================
package com.beginsecure;
import com.azure.identity.ChainedTokenCredential;
import com.azure.identity.DefaultAzureCredential;
import com.azure.identity.ManagedIdentityCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.cosmos.*;
import com.azure.cosmos.CosmosClient;
import com.azure.identity.DefaultAzureCredentialBuilder;
public class CosmosHelper {
private CosmosAsyncClient client;
private String databaseName;
public CosmosHelper(String cosmosEndPoint, String managedIdentity, String dbName) {
System.out.printf(dbName);
DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
.managedIdentityClientId(managedIdentity)
.build();
this.client = new CosmosClientBuilder()
.endpoint(cosmosEndPoint)
.credential(defaultCredential)
.buildAsyncClient();
this.databaseName = dbName;
}
}
=========== End 2.CosmosHelper.java ====================
=========== Start 3.main.java ==========================
package com.beginsecure;
// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.
public class Main {
public static void main(String[] args) {
// Press Alt+Enter with your caret at the highlighted text to see how
// IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");
CosmosHelper tst=new CosmosHelper("https://testdb.documents.azure.com:443/","<Synapse-Work-Space-Identity>","ToDoList");
// Press Shift+F10 or click the green arrow button in the gutter to run the code.
for (int i = 1; i <= 5; i++) {
// Press Shift+F9 to start debugging your code. We have set one breakpoint
// for you, but you can always add more by pressing Ctrl+F8.
System.out.println("i = " + i);
}
}
}
=========== End 3.main.java ==========================
While running above project files with IntelliJ maven and Java code getting below error
java: package com.azure.cosmos does not exist
It should run successfully with out error.