dynamodb:tried to access class com.amazonaws.services.dynamodbv2.document.internal.IteratorSupport

查询dynamodb表数据:

val tableName = "mytable"

    val table = new Table(DynamoDBClientUtil.getDynamoDBClient, tableName)
    val conditionAllQuery = new StringBuilder()
      .append("record_key").append("=").append(":record_key")
      .append(" and #timestamp > :timestamp")
      .toString()
    val querySpec = new QuerySpec()
      .withKeyConditionExpression(conditionAllQuery)
      .withConsistentRead(true)
      .withNameMap(new NameMap().`with`("#timestamp", "timestamp"))
      .withValueMap(new ValueMap()
      .withString(":record_key", "mykey")
      .withLong(":timestamp", "mytime".toLong))
    val iterator = table.query(querySpec).iterator()
    while (iterator.hasNext){
      println(iterator.next())
    }

当用QuerySpec查询dynamodb 表用iterator遍历时,如果是在java环境下,不会报下面错误,但是在scala环境下,就会报下面错误,主要还是包的访问权限造成的

Exception in thread "main" java.lang.IllegalAccessError: tried to access class com.amazonaws.services.dynamodbv2.document.internal.IteratorSupport from class 

解决办法:可采用dynamodb mapper方式接口进行查询,或者用QueryRequest方式:

    val expressionAttributesNames = new util.HashMap[String,String]()
    expressionAttributesNames.put("#record_key","record_key");
    expressionAttributesNames.put("#timestamp","timestamp");

    val  expressionAttributeValues = new util.HashMap[String,AttributeValue]()
    expressionAttributeValues.put(":record_key",new AttributeValue().withS("mykey"));
    expressionAttributeValues.put(":timestamp",new AttributeValue().withN("mytime"));

    val query = new QueryRequest()
      .withTableName(tableName)
      .withKeyConditionExpression("#record_key = :record_key and #timestamp > :timestamp ")
      .withExpressionAttributeNames(expressionAttributesNames)
      .withExpressionAttributeValues(expressionAttributeValues);

    val queryResult = DynamoDBClientUtil.getDynamoDBClient.query(query).getItems


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值