gpt4 book ai didi

java - 无法创建 Azure BlobContainerClient,因为我收到 java.lang.NoClassDefFoundError : com/fasterxml/jackson/core/TSFBuilder

转载 作者:行者123 更新时间:2023-12-03 00:22:57 31 4
gpt4 key购买 nike

我在尝试使用我拥有的凭据创建 Azure blobConatinerClient 时遇到错误。

凭证是instanceOf StorageSharedKeyCredential和端点是instanceOf String

这是代码

 public BlobContainerClient initBlobClient() {
BlobContainerClient blobContainerClient;

StorageSharedKeyCredential credential = new StorageSharedKeyCredential(ACCOUNT_NAME, ACCOUNT_KEY);

String endpoint = String.format(Locale.ROOT, "https://test.blob.core.windows.net");

// Getting the ClassDefError here
BlobServiceClient storageClient = new BlobServiceClientBuilder().endpoint(endpoint).credential(credential).buildClient();

blobContainerClient = storageClient.getBlobContainerClient(CONTAINTER_NAME);

return blobContainerClient;
}

这是触发的堆栈跟踪

    at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:122)
at com.azure.core.util.serializer.JacksonAdapter.<init>(JacksonAdapter.java:76)
at com.azure.core.util.serializer.JacksonAdapter.createDefaultSerializerAdapter(JacksonAdapter.java:109)
at com.azure.core.http.rest.RestProxy.createDefaultSerializer(RestProxy.java:615)
at com.azure.core.http.rest.RestProxy.create(RestProxy.java:667)
at com.azure.storage.blob.implementation.ServicesImpl.<init>(ServicesImpl.java:58)
at com.azure.storage.blob.implementation.AzureBlobStorageImpl.<init>(AzureBlobStorageImpl.java:216)
at com.azure.storage.blob.implementation.AzureBlobStorageBuilder.build(AzureBlobStorageBuilder.java:93)
at com.azure.storage.blob.BlobServiceAsyncClient.<init>(BlobServiceAsyncClient.java:108)
at com.azure.storage.blob.BlobServiceClientBuilder.buildAsyncClient(BlobServiceClientBuilder.java:109)
at com.azure.storage.blob.BlobServiceClientBuilder.buildClient(BlobServiceClientBuilder.java:82)

这些是我拥有的 azure 依赖项。我还添加了 Jackson,因为 StackOverflow 的一条评论说这可以解决问题,但事实并非如此。

    <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.azure/azure-storage-blob -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.9.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.azure/azure-core -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.3.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.projectreactor/reactor-core -->
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.3.4.RELEASE</version>
</dependency>

<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.6.3</version>
</dependency>

<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.33.0</version>
</dependency>

有人可以指出是否缺少某些内容,或者我是否必须在此处更改任何内容?

最佳答案

Azure Storage Blob SDK 仅需要 azure-storage-blob 依赖项。

<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.9.0</version>
</dependency>

还有关于创建容器的示例。

// From the Azure portal, get your Storage account's name and account key. 
String accountName = "";
String accountKey = "";

// Use your Storage account's name and key to create a credential object; this is used to access your account.
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);

// From the Azure portal, get your Storage account blob service URL endpoint.
// The URL typically looks like this:
String endpoint = String.format(Locale.ROOT, "https://%s.blob.core.windows.net", accountName);

// Create a BlobServiceClient object that wraps the service endpoint, credential and a request pipeline.
BlobServiceClient storageClient = new BlobServiceClientBuilder().endpoint(endpoint).credential(credential).buildClient();

// Create the container and return a container client object
BlobContainerClient containerClient = blobServiceClient.createBlobContainer(containerName);

请尝试遵循此quickstart创建maven项目。

关于java - 无法创建 Azure BlobContainerClient,因为我收到 java.lang.NoClassDefFoundError : com/fasterxml/jackson/core/TSFBuilder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65253479/

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