【问题标题】:java Azure create table if not exists into table storagejava Azure 如果不存在则创建表到表存储中
【发布时间】:2019-04-04 23:31:45
【问题描述】:

为什么我在尝试create table into table storage时会出现以下错误:

com.microsoft.azure.storage.StorageException:好的 在 com.microsoft.azure.storage.StorageException.translateException(StorageException.java:87) 在 com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:209) 在 com.microsoft.azure.storage.table.QueryTableOperation.performRetrieve(QueryTableOperation.java:178) 在 com.microsoft.azure.storage.table.TableOperation.execute(TableOperation.java:694) 在 com.microsoft.azure.storage.table.CloudTable.exists(CloudTable.java:888) 在 com.microsoft.azure.storage.table.CloudTable.createIfNotExists(CloudTable.java:290) 在 com.microsoft.azure.storage.table.CloudTable.createIfNotExists(CloudTable.java:265) 在 be.dela.gdprvault.test.StorageTestClient.getTableByName(StorageTestClient.groovy:25) 在 be.dela.gdprvault.logging.entity.ActionLogSystemSpec.getActionLogFromTableByPartitionAndRowKey(ActionLogSystemSpec.groovy:114) 在 be.dela.gdprvault.logging.entity.ActionLogSystemSpec.should 保存 ActionLog 实体到表存储(ActionLogSystemSpec.groovy:96) 引起:java.lang.NullPointerException 在 com.microsoft.azure.storage.table.TableDeserializer.parseJsonEntity(TableDeserializer.java:290) 在 com.microsoft.azure.storage.table.TableDeserializer.parseSingleOpResponse(TableDeserializer.java:203) 在 com.microsoft.azure.storage.table.QueryTableOperation.parseResponse(QueryTableOperation.java:143) 在 com.microsoft.azure.storage.table.QueryTableOperation$1.postProcessResponse(QueryTableOperation.java:236) 在 com.microsoft.azure.storage.table.QueryTableOperation$1.postProcessResponse(QueryTableOperation.java:193) 在 com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:155) ... 8 更多

docer-compose
  azure-blob-storage:
    image: arafato/azurite
    ports:
      - "10000:10000"
      - "10002:10002"
    volumes:
      - data-volume:/opt/azurite/folder

    CloudTable table = tableClient.getTableReference(tableName)
    table.createIfNotExists() -- there is error

我按照https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-java的文章做了

【问题讨论】:

  • 您是否确认连接字符串正确并正确创建tableClient
  • 您好,请发布您的具体 java 代码,以便我可以帮助您。
  • 谢谢,我已经准备好代码transfiles.ru/9jeo3。运行 azure.storage.logging.entity.ActionLogSystemSpec。我尝试保存复杂的类 azure.storage.logging.entity.ActionLog,所以我将 ActionLog 转换为 ActionLogWrapper

标签: azure azure-table-storage


【解决方案1】:

我试图重现您的异常但失败了。您可以使用Fiddler 捕获您的Java 代码的请求和响应,以检查状态码和错误详情。

你可以参考我的工作代码:

import com.microsoft.azure.storage.*;
import com.microsoft.azure.storage.table.*;

public class CreateTableTest {

    public static final String storageConnectionString =
            "DefaultEndpointsProtocol=https;" +
                    "AccountName=***;" +
                    "AccountKey=***;" +
                    "TableEndpoint=https://***.table.cosmosdb.azure.com:443/;" ;

    public static void main(String[] args) {

        try
        {
            // Retrieve storage account from connection-string.
            CloudStorageAccount storageAccount =
                    CloudStorageAccount.parse(storageConnectionString);

            // Create the table client.
            CloudTableClient tableClient = storageAccount.createCloudTableClient();

            // Create the table if it doesn't exist.
            String tableName = "people";
            CloudTable cloudTable = tableClient.getTableReference(tableName);
            cloudTable.createIfNotExists();

            System.out.println("Create Success...");
        }
        catch (Exception e)
        {
            // Output the stack trace.
            e.printStackTrace();
        }

    }
}

我的sdk版本是:

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

【讨论】:

  • 谢谢,我已经准备好代码 [link]transfiles.ru/9jeo3。运行 azure.storage.logging.entity.ActionLogSystemSpec。是集成测试。我尝试保存复杂的类 azure.storage.logging.entity.ActionLog,所以我将 ActionLog 转换为 ActionLogWrapper
  • 所以,事实上,它与 azure storage sdk 本身无关,对吧?
  • 我的代码在生产中工作,但是当我尝试编写集成代码时,我得到了错误。所以我不知道为什么会发生
  • @АлександрШинкевич 如果您不在问题中分享示例代码,则很难调查问题。
  • 我还将项目添加到存储库github.com/AlexandrShinkevich87/azure
猜你喜欢
  • 1970-01-01
  • 2020-03-28
  • 2010-12-03
  • 1970-01-01
  • 2013-05-26
  • 2016-02-15
  • 2010-09-19
  • 2023-03-22
相关资源
最近更新 更多