无法创建azure blobcontainerclient,因为我正在获取java.lang.noclassdeffounderror:com/fasterxml/jackson/core/tsfbuilder

yqhsw0fo  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(904)

我在尝试使用我拥有的凭据创建azure BlobCenter客户端时遇到错误。
凭据是storagesharedkeycredential的instanceof,终结点是string的instanceof
这是密码

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)

这些都是我拥有的。我还添加了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>

有人能指出是不是少了什么东西,或者是我有什么需要改变的吗?

a1o7rhls

a1o7rhls1#

只有依赖 azure-storage-blob azure存储blob sdk需要。

<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);

请尝试按照这个快速启动来创建maven项目。

相关问题