Amazon DynamoDB Java 客户端 – NoSuchMethodError

huangapple go评论90阅读模式
英文:

Amazon dynamo db java client - NoSuchMethodError

问题

public static void main(String[] args) {

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

    Table table = dynamoDB.getTable("attestation-db");

    // Build a list of related items
    List<Number> relatedItems = new ArrayList<Number>();
    relatedItems.add(341);
    relatedItems.add(472);
    relatedItems.add(649);

    // Build a map of product pictures
    Map<String, String> pictures = new HashMap<String, String>();
    pictures.put("FrontView", "http://example.com/products/123_front.jpg");
    pictures.put("RearView", "http://example.com/products/123_rear.jpg");
    pictures.put("SideView", "http://example.com/products/123_left_side.jpg");

    // Build a map of product reviews
    Map<String, List<String>> reviews = new HashMap<String, List<String>>();

    List<String> fiveStarReviews = new ArrayList<String>();
    fiveStarReviews.add("Excellent! Can't recommend it highly enough!  Buy it!");
    fiveStarReviews.add("Do yourself a favor and buy this");
    reviews.put("FiveStar", fiveStarReviews);

    List<String> oneStarReviews = new ArrayList<String>();
    oneStarReviews.add("Terrible product!  Do not buy this.");
    reviews.put("OneStar", oneStarReviews);

    // Build the item
    Item item = new Item()
            .withPrimaryKey("Id", 123)
            .withString("Title", "Bicycle 123")
            .withString("Description", "123 description")
            .withString("BicycleType", "Hybrid")
            .withString("Brand", "Brand-Company C")
            .withNumber("Price", 500)
            .withStringSet("Color", new HashSet<String>(Arrays.asList("Red", "Black")))
            .withString("ProductCategory", "Bicycle")
            .withBoolean("InStock", true)
            .withNull("QuantityOnHand")
            .withList("RelatedItems", relatedItems)
            .withMap("Pictures", pictures)
            .withMap("Reviews", reviews);

    // Write the item to the table
    PutItemOutcome outcome = table.putItem(item);
}
英文:

Trying to run a local amazon dynamo db client with the following code which is basically just a sample i have gotten online, I have created the table with local stack so it should exist not really sure what the issue is.

	public static void main(String[] args) {
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable(&quot;attestation-db&quot;);
// Build a list of related items
List&lt;Number&gt; relatedItems = new ArrayList&lt;Number&gt;();
relatedItems.add(341);
relatedItems.add(472);
relatedItems.add(649);
//Build a map of product pictures
Map&lt;String, String&gt; pictures = new HashMap&lt;String, String&gt;();
pictures.put(&quot;FrontView&quot;, &quot;http://example.com/products/123_front.jpg&quot;);
pictures.put(&quot;RearView&quot;, &quot;http://example.com/products/123_rear.jpg&quot;);
pictures.put(&quot;SideView&quot;, &quot;http://example.com/products/123_left_side.jpg&quot;);
//Build a map of product reviews
Map&lt;String, List&lt;String&gt;&gt; reviews = new HashMap&lt;String, List&lt;String&gt;&gt;();
List&lt;String&gt; fiveStarReviews = new ArrayList&lt;String&gt;();
fiveStarReviews.add(&quot;Excellent! Can&#39;t recommend it highly enough!  Buy it!&quot;);
fiveStarReviews.add(&quot;Do yourself a favor and buy this&quot;);
reviews.put(&quot;FiveStar&quot;, fiveStarReviews);
List&lt;String&gt; oneStarReviews = new ArrayList&lt;String&gt;();
oneStarReviews.add(&quot;Terrible product!  Do not buy this.&quot;);
reviews.put(&quot;OneStar&quot;, oneStarReviews);
// Build the item
Item item = new Item()
.withPrimaryKey(&quot;Id&quot;, 123)
.withString(&quot;Title&quot;, &quot;Bicycle 123&quot;)
.withString(&quot;Description&quot;, &quot;123 description&quot;)
.withString(&quot;BicycleType&quot;, &quot;Hybrid&quot;)
.withString(&quot;Brand&quot;, &quot;Brand-Company C&quot;)
.withNumber(&quot;Price&quot;, 500)
.withStringSet(&quot;Color&quot;,  new HashSet&lt;String&gt;(Arrays.asList(&quot;Red&quot;, &quot;Black&quot;)))
.withString(&quot;ProductCategory&quot;, &quot;Bicycle&quot;)
.withBoolean(&quot;InStock&quot;, true)
.withNull(&quot;QuantityOnHand&quot;)
.withList(&quot;RelatedItems&quot;, relatedItems)
.withMap(&quot;Pictures&quot;, pictures)
.withMap(&quot;Reviews&quot;, reviews);
// Write the item to the table
PutItemOutcome outcome = table.putItem(item);

but i keep getting the following error when i run the main method.

Exception in thread &quot;main&quot; java.lang.NoSuchMethodError: com.amazonaws.util.StringUtils.trim(Ljava/lang/String;)Ljava/lang/String;
at com.amazonaws.auth.profile.internal.AwsProfileNameLoader.getEnvProfileName(AwsProfileNameLoader.java:72)
at com.amazonaws.auth.profile.internal.AwsProfileNameLoader.loadProfileName(AwsProfileNameLoader.java:54)
at com.amazonaws.regions.AwsProfileRegionProvider.&lt;init&gt;(AwsProfileRegionProvider.java:40)
at com.amazonaws.regions.DefaultAwsRegionProviderChain.&lt;init&gt;(DefaultAwsRegionProviderChain.java:23)
at com.amazonaws.client.builder.AwsClientBuilder.&lt;clinit&gt;(AwsClientBuilder.java:58)
at com.lmig.global.event.framework.sample.publisher.application.code.Attestation.main(Attestation.java:18)

答案1

得分: 1

似乎在类路径中存在许多版本的SDK。您可以尝试打印出类被加载的位置。

System.out.println(StringUtils.getClass().getProtectionDomain().getCodeSource());
System.out.println(AwsProfileNameLoader.getClass().getProtectionDomain().getCodeSource());
英文:

It seems there are many versions of SDK present in classpath. can you try print the locations where classes are being loaded.

System.out.println(StringUtils.getClass().getProtectionDomain().getCodeSource());
System.out.println(AwsProfileNameLoader.getClass().getProtectionDomain().getCodeSource());
</details>

huangapple
  • 本文由 发表于 2020年4月6日 17:49:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/61057042.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定