首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在java中使用cosmosDB sdk时出现ALLOW_TRAILING_COMMA错误

在java中使用cosmosDB sdk时出现ALLOW_TRAILING_COMMA错误
EN

Stack Overflow用户
提问于 2020-01-07 22:42:49
回答 1查看 532关注 0票数 0

我在使用cosmosdb for Java时遇到以下异常:

代码语言:javascript
复制
Exception in thread "main" java.lang.NoSuchFieldError: ALLOW_TRAILING_COMMA
    at com.microsoft.azure.cosmosdb.internal.Utils.<clinit>(Utils.java:75)
    at com.microsoft.azure.cosmosdb.rx.internal.RxDocumentClientImpl.<clinit>(RxDocumentClientImpl.java:132)
    at com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient$Builder.build(AsyncDocumentClient.java:224)
    at Program2.<init>(Program2.java:25) 
    at Program2.main(Program2.java:30) 

我只是想用AsyncDocumentClient连接到CosmosDB。异常就发生在那一刻。

代码语言:javascript
复制
executorService = Executors.newFixedThreadPool(100); 
scheduler = Schedulers.from(executorService); 

client = new AsyncDocumentClient.Builder()
          .withServiceEndpoint("[cosmosurl]")
          .withMasterKeyOrResourceToken("[mykey]")
          .withConnectionPolicy(ConnectionPolicy.GetDefault())
          .withConsistencyLevel(ConsistencyLevel.Eventual)
          .build(); 

我听说了一些库冲突,但我还没有找到正确的修复方法。

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2020-01-08 11:11:31

请参考我的工作样本。

Java代码:

代码语言:javascript
复制
import com.microsoft.azure.cosmosdb.ConnectionPolicy;
import com.microsoft.azure.cosmosdb.ConsistencyLevel;
import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient;
public class test {

    public static void main(String[] args) throws Exception {

        AsyncDocumentClient client = new AsyncDocumentClient.Builder()
                .withServiceEndpoint("https://XXX.documents.azure.com:443/")
                .withMasterKeyOrResourceToken("XXXX")
                .withConnectionPolicy(ConnectionPolicy.GetDefault())
                .withConsistencyLevel(ConsistencyLevel.Eventual)
                .build();
        System.out.println(client);
    }
}

pom.xml

代码语言:javascript
复制
<dependencies>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-cosmosdb</artifactId>
        <version>2.6.4</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-cosmosdb-commons</artifactId>
        <version>2.6.4</version>
    </dependency>
</dependencies>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59630653

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档