首页 > 解决方案 > Azure CosmosDB Java Springboot 中的无服务器帐户不支持在容器上设置优惠吞吐量或自动驾驶仪

问题描述

从 Spring Boot 应用程序连接到 Azure CosmosDB 时出错。

代码 :

<dependency>
  <groupId>com.microsoft.azure</groupId>
  <artifactId>spring-data-cosmosdb</artifactId>
  <version>2.3.0</version>
</dependency>

@Bean
public CosmosDBConfig getConfig() {
    this.cosmosKeyCredential = new CosmosKeyCredential(key);
    CosmosDBConfig cosmosdbConfig = CosmosDBConfig.builder(uri, this.cosmosKeyCredential, dbName)
            .build();
    return cosmosdbConfig;
}

@Repository
public interface UserRepository extends CosmosRepository<User, String> {}

错误信息 :

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate 
[com.microsoft.azure.spring.data.cosmosdb.repository.support.SimpleCosmosRepository]: 
Constructor threw exception; nested exception is com.microsoft.azure.spring.data.cosmosdb.exception.CosmosDBAccessException: 
Failed to create container; nested exception is CosmosClientException{error={"code":"BadRequest","message":"Setting offer throughput or autopilot on container is not supported for serverless accounts.\r\n
ActivityId: 7e165926-0a0b-43a5-92a8-8e46fef98b47, Microsoft.Azure.Documents.Common/2.14.0, 
StatusCode: BadRequest","additionalErrorInfo":null}, resourceAddress='null', statusCode=400, 
message=Setting offer throughput or autopilot on container is not supported for serverless accounts.

标签: javaspring-bootazureazure-cosmosdb

解决方案


推荐阅读