Amazon DynamoDB Java 客户端 – NoSuchMethodError

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

Amazon dynamo db java client - NoSuchMethodError

问题

  1. public static void main(String[] args) {
  2. AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
  3. DynamoDB dynamoDB = new DynamoDB(client);
  4. Table table = dynamoDB.getTable("attestation-db");
  5. // Build a list of related items
  6. List<Number> relatedItems = new ArrayList<Number>();
  7. relatedItems.add(341);
  8. relatedItems.add(472);
  9. relatedItems.add(649);
  10. // Build a map of product pictures
  11. Map<String, String> pictures = new HashMap<String, String>();
  12. pictures.put("FrontView", "http://example.com/products/123_front.jpg");
  13. pictures.put("RearView", "http://example.com/products/123_rear.jpg");
  14. pictures.put("SideView", "http://example.com/products/123_left_side.jpg");
  15. // Build a map of product reviews
  16. Map<String, List<String>> reviews = new HashMap<String, List<String>>();
  17. List<String> fiveStarReviews = new ArrayList<String>();
  18. fiveStarReviews.add("Excellent! Can't recommend it highly enough! Buy it!");
  19. fiveStarReviews.add("Do yourself a favor and buy this");
  20. reviews.put("FiveStar", fiveStarReviews);
  21. List<String> oneStarReviews = new ArrayList<String>();
  22. oneStarReviews.add("Terrible product! Do not buy this.");
  23. reviews.put("OneStar", oneStarReviews);
  24. // Build the item
  25. Item item = new Item()
  26. .withPrimaryKey("Id", 123)
  27. .withString("Title", "Bicycle 123")
  28. .withString("Description", "123 description")
  29. .withString("BicycleType", "Hybrid")
  30. .withString("Brand", "Brand-Company C")
  31. .withNumber("Price", 500)
  32. .withStringSet("Color", new HashSet<String>(Arrays.asList("Red", "Black")))
  33. .withString("ProductCategory", "Bicycle")
  34. .withBoolean("InStock", true)
  35. .withNull("QuantityOnHand")
  36. .withList("RelatedItems", relatedItems)
  37. .withMap("Pictures", pictures)
  38. .withMap("Reviews", reviews);
  39. // Write the item to the table
  40. PutItemOutcome outcome = table.putItem(item);
  41. }
英文:

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.

  1. public static void main(String[] args) {
  2. AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
  3. DynamoDB dynamoDB = new DynamoDB(client);
  4. Table table = dynamoDB.getTable(&quot;attestation-db&quot;);
  5. // Build a list of related items
  6. List&lt;Number&gt; relatedItems = new ArrayList&lt;Number&gt;();
  7. relatedItems.add(341);
  8. relatedItems.add(472);
  9. relatedItems.add(649);
  10. //Build a map of product pictures
  11. Map&lt;String, String&gt; pictures = new HashMap&lt;String, String&gt;();
  12. pictures.put(&quot;FrontView&quot;, &quot;http://example.com/products/123_front.jpg&quot;);
  13. pictures.put(&quot;RearView&quot;, &quot;http://example.com/products/123_rear.jpg&quot;);
  14. pictures.put(&quot;SideView&quot;, &quot;http://example.com/products/123_left_side.jpg&quot;);
  15. //Build a map of product reviews
  16. Map&lt;String, List&lt;String&gt;&gt; reviews = new HashMap&lt;String, List&lt;String&gt;&gt;();
  17. List&lt;String&gt; fiveStarReviews = new ArrayList&lt;String&gt;();
  18. fiveStarReviews.add(&quot;Excellent! Can&#39;t recommend it highly enough! Buy it!&quot;);
  19. fiveStarReviews.add(&quot;Do yourself a favor and buy this&quot;);
  20. reviews.put(&quot;FiveStar&quot;, fiveStarReviews);
  21. List&lt;String&gt; oneStarReviews = new ArrayList&lt;String&gt;();
  22. oneStarReviews.add(&quot;Terrible product! Do not buy this.&quot;);
  23. reviews.put(&quot;OneStar&quot;, oneStarReviews);
  24. // Build the item
  25. Item item = new Item()
  26. .withPrimaryKey(&quot;Id&quot;, 123)
  27. .withString(&quot;Title&quot;, &quot;Bicycle 123&quot;)
  28. .withString(&quot;Description&quot;, &quot;123 description&quot;)
  29. .withString(&quot;BicycleType&quot;, &quot;Hybrid&quot;)
  30. .withString(&quot;Brand&quot;, &quot;Brand-Company C&quot;)
  31. .withNumber(&quot;Price&quot;, 500)
  32. .withStringSet(&quot;Color&quot;, new HashSet&lt;String&gt;(Arrays.asList(&quot;Red&quot;, &quot;Black&quot;)))
  33. .withString(&quot;ProductCategory&quot;, &quot;Bicycle&quot;)
  34. .withBoolean(&quot;InStock&quot;, true)
  35. .withNull(&quot;QuantityOnHand&quot;)
  36. .withList(&quot;RelatedItems&quot;, relatedItems)
  37. .withMap(&quot;Pictures&quot;, pictures)
  38. .withMap(&quot;Reviews&quot;, reviews);
  39. // Write the item to the table
  40. PutItemOutcome outcome = table.putItem(item);

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

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

答案1

得分: 1

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

  1. System.out.println(StringUtils.getClass().getProtectionDomain().getCodeSource());
  2. 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.

  1. System.out.println(StringUtils.getClass().getProtectionDomain().getCodeSource());
  2. System.out.println(AwsProfileNameLoader.getClass().getProtectionDomain().getCodeSource());
  3. </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:

确定