Amazon Dynamo DB java клиент - NoSuchMethodError - PullRequest
1 голос
/ 06 апреля 2020

Пытаясь запустить локальный клиент Amazon Amazon Dynamo DB со следующим кодом, который в основном является просто примером, который я получил в Интернете, я создал таблицу с локальным стеком, поэтому она должна существовать, не зная точно, в чем проблема.

    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);

но я продолжаю получать следующую ошибку при запуске основного метода.

Exception in thread "main" 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.<init>(AwsProfileRegionProvider.java:40)
    at com.amazonaws.regions.DefaultAwsRegionProviderChain.<init>(DefaultAwsRegionProviderChain.java:23)
    at com.amazonaws.client.builder.AwsClientBuilder.<clinit>(AwsClientBuilder.java:58)
    at com.lmig.global.event.framework.sample.publisher.application.code.Attestation.main(Attestation.java:18)

1 Ответ

1 голос
/ 06 апреля 2020

Похоже, в classpath присутствует много версий SDK. Можете ли вы попробовать распечатать места загрузки классов.

System.out.println(StringUtils.getClass().getProtectionDomain().getCodeSource());
System.out.println(AwsProfileNameLoader.getClass().getProtectionDomain().getCodeSource());
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...