gpt4 book ai didi

amazon-dynamodb - AmazonDynamoDBClientBuilder.standard 无法解析为类型

转载 作者:行者123 更新时间:2023-12-02 00:44:11 26 4
gpt4 key购买 nike

我正在尝试遵循基本的 AWS 教程,在 AWS 无服务器设置的 java 运行时环境中与 DynamoDB 进行交互。但是,由于某种原因,当我尝试创建新的 AmazonDynamoDBClientBuilder 时,Eclipse 抛出错误

我仔细检查后发现 POM.xml 中记录了正确的依赖项,但是我仍然收到错误“AmazonDynamoDBClientBuilder.standard 无法解析为类型”

代码:

package com.serverless.demo.function;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;

import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.dynamodbv2.document.Table;
import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
import com.amazonaws.services.dynamodbv2.model.KeyType;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType;


public class HelloWorld implements RequestHandler<String, String> {
@Override
public String handleRequest(String input, Context context) {

AmazonDynamoDB client = new AmazonDynamoDBClientBuilder.standard().build();

}
}

最佳答案

你能发布你的maven.xml吗?

您应该具有以下依赖项:

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.11.163</version>
</dependency>

在 mvnrepository [here] 上检查存档的最新版本.

或者一个 Maven 文件结构如下:

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.166</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
</dependency>
</dependencies>

请注意:

此答案是在没有第二版 AWS 开发工具包时给出的。在 AWS SDK v2 中,您的类以 software.amazon.awssdk 为前缀。它们不再像 AWS SDK v1 中那样驻留在以 com.amazonaws 为前缀的包中。

使用 AWS SDK v2,您可以按如下方式设置 Maven BOM( Material list ):

<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.20.78</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

有关设置 Maven 项目的 AWS 文档,请查看 [here] 。有关最新版本的 AWS BOM 检查 [here] .

关于amazon-dynamodb - AmazonDynamoDBClientBuilder.standard 无法解析为类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43920870/

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