java - 使用 AWS 开发工具包的 java.lang.NoSuchMethodError
问题描述
我正在尝试使用以下代码将图像上传到 Amazon S3 存储桶:
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withRegion("us-east-1")
.withCredentials(credentialsProvider)
.build();
但是,Eclipse 会抛出以下异常:
Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:537)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:448)
at com.amazonaws.partitions.PartitionsLoader.<clinit>(PartitionsLoader.java:51)
at com.amazonaws.regions.RegionMetadataFactory.create(RegionMetadataFactory.java:30)
at com.amazonaws.regions.RegionUtils.initialize(RegionUtils.java:64)
at com.amazonaws.regions.RegionUtils.getRegionMetadata(RegionUtils.java:52)
at com.amazonaws.regions.RegionUtils.getRegion(RegionUtils.java:105)
at com.amazonaws.client.builder.AwsClientBuilder.getRegionObject(AwsClientBuilder.java:249)
at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:238)
at order_fulfilment.amazon.AmazonS3API.perform(AmazonS3API.java:68)
at amzn.Main.main(Main.java:126)
基于这个线程,这似乎是杰克逊版本的问题。但是,我尝试了 Jackson 的每个版本(包括版本 2.6.7 和 2.6.6。如线程中所建议的)都无济于事。
我能够使用以下代码确认杰克逊版本是正确的:
System.out.println(com.fasterxml.jackson.databind.ObjectMapper.class.getProtectionDomain().getCodeSource().getLocation());
正如这个和这个关于stackoverflow的线程所建议的那样。
我究竟做错了什么?
所有依赖项:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>amz</groupId>
<artifactId>amz</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>lib</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.ashot</groupId>
<artifactId>ashot</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-sheets</artifactId>
<version>v4-rev520-1.23.0</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.geronimo.gshell.support</groupId>
<artifactId>gshell-io</artifactId>
<version>1.0-alpha-2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.358</version>
</dependency>
</dependencies>
</project>
注意:我玩过每个依赖项的许多不同版本(这是我尝试过的最新版本),但它们都会导致相同的错误。
解决方案
推荐阅读
- reactjs - 在 React Router v6 中,如何在离开页面/路由之前检查表单是否脏
- authentication - Hyperledger Explorer 登录页面 禁用
- leaflet - 传单:第一次加载地图时加载了多少瓦片?
- angular - Angular,ngClass,使用函数来评估元素类-性能和最佳实践方法
- python - 如何在单次通话中将字典发布到 Google 表格
- r - 更新 R 后安装包时编译错误
- azure - Set-AzureADUserPassword - 密码是否通过 AAD Connect 写回本地域?
- c - 包含 gtk GSList 的函数存在问题
- memory-management - 如何拆分分配区域,以便可以分别重新分配两个区域?
- javascript - 从 Google Analytics(分析)用户资源管理器中批量导出单个用户的 JSON 数据