尝试实施AWS SDK时出现异常

时间:2015-07-23 17:54:07

标签: java spring apache-httpclient-4.x aws-sdk

尝试将AWS SDK实施到Java Web应用程序时遇到错误。我试图编写一个简单的方法将图像保存到S3 Bucket,当我触发该方法时会发生错误。

堆栈跟踪

SEVERE: Servlet.service() for servlet dispatcher threw exception
java.lang.NoSuchMethodError: org.apache.http.params.HttpConnectionParams.setSoKeepalive(Lorg/apache/http/params/HttpParams;Z)V
    at com.amazonaws.http.HttpClientFactory.createHttpClient(HttpClientFactory.java:95)
    at com.amazonaws.http.AmazonHttpClient.<init>(AmazonHttpClient.java:198)
    at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:129)
    at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:434)
    at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:416)
    at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:400)
    at com.artistbomb.common.CommonUtility.saveImage(CommonUtility.java:254)

根据我在Google上看到的内容,我觉得此问题与我的Build Path配置错误有关。我已经包含了所有的AWS罐子以及所有第三方罐子,并且我已经完成并删除了旧版本的库。

类路径

<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/json-lib-2.4-jdk15.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-security-acl-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-security-aspects-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-security-config-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-security-core-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-security-taglibs-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-security-web-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/activation-1.1.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/anet-java-sdk-1.4.6.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/antlr-2.7.6.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/aopalliance-1.0.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/asm-3.1.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/cglib-2.2.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-beanutils-1.7.0.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-cli-1.2.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-codec-1.6.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-collections-3.1.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-dbcp-all-1.3.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-digester-2.0.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-discovery-0.2.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-fileupload-1.2.2.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-io-1.4.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-lang-2.3.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-logging-1.1.3.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-pool-1.5.4.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-validator-1.4.0.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/dom4j-1.6.1.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/ehcache-core-2.3.1.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/ehcache-spring-annotations-1.2.0.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/ezmorph-1.0.6.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate-commons-annotations-3.2.0.Final.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate-core-3.6.1.Final.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate-entitymanager-3.6.1.Final.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate-jpa-2.0-api-1.0.0.Final.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate-validator-4.1.0.Final.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/httpcore-4.3.3.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/httpclient-4.3.6.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/httpclient-cache-4.3.3.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/httpmime-4.3.3.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/jackson-all-1.9.5.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/jackson-annotations-2.5.3.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/jackson-core-2.5.3.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/jackson-databind-2.5.3.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/javassist-3.12.0.GA.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/javax.mail-api-1.4.6.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/jstl-1.2.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/jta-1.1.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/log4j-1.2.12.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/mail-1.4.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/mysql-connector-java-5.1.18.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/quartz-1.8.6.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/restfb-1.6.9.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/scribe-1.3.0.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/slf4j-api-1.6.1.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/slf4j-log4j12-1.6.1.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-aop-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-asm-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-beans-3.0.7.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-context-3.0.7.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-context-support-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-core-3.0.7.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-expression-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-jdbc-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-mock-2.0.8.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-orm-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-tx-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-web-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-webmvc-3.0.5.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/validation-api-1.0.0.GA.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/xerces-2.6.2.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/xercesImpl.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/xml-apis.jar"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/servlet-api.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/yuicompressor-2.4.7.jar"/>
    <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/aspectjrt.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/aspectjweaver.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/joda-time-2.8.1.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/freemarker-2.3.18.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/ecwid-mailchimp.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/fluent-hc-4.3.3.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/gson-2.2.4.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/guava-17.0.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/java-lutung-mandrill.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/aws-java-sdk-1.10.5.1-javadoc.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/aws-java-sdk-1.10.5.1-sources.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/aws-java-sdk-flow-build-tools-1.10.5.1.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/aws-java-sdk-1.10.5.1.jar"/>
    <classpathentry kind="output" path="build/classes"/>
</classpath>

1 个答案:

答案 0 :(得分:6)

事实证明,我的项目/ WebContent / WEB-INF / lib目录中有几个旧的库版本导致了依赖性问题。从构建路径以及 lib目录中删除重复的旧库是非常重要的。