gpt4 book ai didi

java - 使用 cosmosdb Spring Boot Starter 的示例 Spring Boot 应用程序无法启动,输入字节数组在 88 处的结束字节不正确

转载 作者:行者123 更新时间:2023-12-01 16:14:09 25 4
gpt4 key购买 nike

我试图使用 cosmos DB Document API 制作一个简单的 Spring Boot 应用程序(Table API 也是一个选项)

已关注 this示例并使用 local-emulator

Spring 启动2.3Azure Spring Boot:2.3.1

应用程序无法引导:

    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
... 71 common frames omitted
Caused by: java.lang.IllegalArgumentException: Input byte array has incorrect ending byte at 88
at java.util.Base64$Decoder.decode0(Base64.java:742) ~[na:1.8.0_241]
at java.util.Base64$Decoder.decode(Base64.java:526) ~[na:1.8.0_241]
at com.azure.data.cosmos.internal.BaseAuthorizationTokenProvider.getMacInstance(BaseAuthorizationTokenProvider.java:251) ~[azure-cosmos-3.7.3.jar:na]
at com.azure.data.cosmos.internal.BaseAuthorizationTokenProvider.<init>(BaseAuthorizationTokenProvider.java:36) ~[azure-cosmos-3.7.3.jar:na]
at com.azure.data.cosmos.internal.RxDocumentClientImpl.<init>(RxDocumentClientImpl.java:200) ~[azure-cosmos-3.7.3.jar:na]
at com.azure.data.cosmos.internal.RxDocumentClientImpl.<init>(RxDocumentClientImpl.java:135) ~[azure-cosmos-3.7.3.jar:na]
at com.azure.data.cosmos.internal.RxDocumentClientImpl.<init>(RxDocumentClientImpl.java:124) ~[azure-cosmos-3.7.3.jar:na]
at com.azure.data.cosmos.internal.AsyncDocumentClient$Builder.build(AsyncDocumentClient.java:177) ~[azure-cosmos-3.7.3.jar:na]
at com.azure.data.cosmos.CosmosClient.<init>(CosmosClient.java:54) ~[azure-cosmos-3.7.3.jar:na]
at com.azure.data.cosmos.CosmosClientBuilder.build(CosmosClientBuilder.java:203) ~[azure-cosmos-3.7.3.jar:na]

Here用于重现错误的存储库,位于主文件下方配置文件:

@Slf4j
@Configuration
@EnableCosmosRepositories
public class CosmosConfiguration extends AbstractCosmosConfiguration {

@Value("${azure.cosmosdb.uri}")
private String uri;

@Value("${azure.cosmosdb.key}")
private String key;

@Value("${azure.cosmosdb.secondaryKey}")
private String secondaryKey;

@Value("${azure.cosmosdb.database}")
private String dbName;

@Value("${azure.cosmosdb.populateQueryMetrics}")
private boolean populateQueryMetrics;

private CosmosKeyCredential cosmosKeyCredential;

private static class ResponseDiagnosticsProcessorImplementation implements ResponseDiagnosticsProcessor {

@Override
public void processResponseDiagnostics(@Nullable ResponseDiagnostics responseDiagnostics) {
log.info("Response Diagnostics {}", responseDiagnostics);
}
}

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

public void switchToSecondaryKey() {
this.cosmosKeyCredential.key(secondaryKey);
}
}

bean :

@Builder
@AllArgsConstructor
@Data
@Document
//@Document(collection = "testCosmos")
public class Entity {

@Id
@PartitionKey
private String id;

private String value;
}

存储库(我不想使用响应式(Reactive)存储库):

@Repository
public interface SimpleRepository extends CosmosRepository<Entity, String> {
}

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/>
</parent>

<groupId>com.github.paizo</groupId>
<artifactId>cosmos</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>cosmos</name>
<description>Demo project for Spring Boot and Cosmos</description>

<properties>
<java.version>1.8</java.version>
<azure.version>2.3.2</azure.version>
<spring-boot.version>2.3.0.RELEASE</spring-boot.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-cosmosdb-spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</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>

</project>

您对无法启动的原因有什么建议吗?如果我不定义自定义 Cosmos 配置类,结果不会改变

我没有使用响应式(Reactive)存储库,因为我想在现有的 jpa 应用程序中使用 cosmos,而 webflux 对 jpa 不满意。

最佳答案

Azure Cosmos DB 的 Spring Data不能用于表 API。它只能与 SQL API 一起使用。

关于java - 使用 cosmosdb Spring Boot Starter 的示例 Spring Boot 应用程序无法启动,输入字节数组在 88 处的结束字节不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62448819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com