web-dev-qa-db-ja.com

aws-Java-sdk-s3の使用中にエラーが発生しました

非常に基本的なテストでs3sdkを実行しようとしていますが、エラーが発生します。

原因:Java.lang.NoSuchFieldError:SIGNING_REGION at com.amazonaws.services.s3.AmazonS3Client.createRequest(AmazonS3Client.Java:4227)at com.amazonaws.services.s3.AmazonS3Client.createRequest(AmazonS3Client.Java:4203)at com .amazonaws.services.s3.AmazonS3Client.listBuckets(AmazonS3Client.Java:929)at com.amazonaws.services.s3.AmazonS3Client.listBuckets(AmazonS3Client.Java:936)

aws-Java-sdk-s3

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-Java-sdk-s3</artifactId>
<version>1.11.288</version>
</dependency

    ClientConfiguration cf = new ClientConfiguration();
    AWSCredentials credentials = new BasicAWSCredentials("<id>","<secret>");
    AmazonS3 amazonS3Client= 
    AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion(Regions.US_EAST_1).build();
    List<Bucket> buckets = amazonS3Client.listBuckets();

Maven依存関係ツリー:

O] --- maven-dependency-plugin:2.10:tree (default-cli) @ AwsSdkDemo ---
O] com.example:AwsSdkDemo:jar:0.0.1-SNAPSHOT
O] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.5.10.RELEASE:compile
O] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.10.RELEASE:compile
O] |  |  +- org.springframework.boot:spring-boot:jar:1.5.10.RELEASE:compile
O] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.10.RELEASE:compile
O] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.10.RELEASE:compile
O] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
O] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
O] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
O] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
O] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
O] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.5.10.RELEASE:compile
O] |  |  +- org.springframework:spring-aop:jar:4.3.14.RELEASE:compile
O] |  |  \- org.aspectj:aspectjweaver:jar:1.8.13:compile
O] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.5.10.RELEASE:compile
O] |  |  +- org.Apache.Tomcat:tomcat-jdbc:jar:8.5.27:compile
O] |  |  |  \- org.Apache.Tomcat:tomcat-juli:jar:8.5.27:compile
O] |  |  \- org.springframework:spring-jdbc:jar:4.3.14.RELEASE:compile
O] |  +- org.hibernate:hibernate-core:jar:5.0.12.Final:compile
O] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
O] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
O] |  |  +- org.javassist:javassist:jar:3.21.0-GA:compile
O] |  |  +- antlr:antlr:jar:2.7.7:compile
O] |  |  +- org.jboss:jandex:jar:2.0.0.Final:compile
O] |  |  +- dom4j:dom4j:jar:1.6.1:compile
O] |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
O] |  +- org.hibernate:hibernate-entitymanager:jar:5.0.12.Final:compile
O] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
O] |  +- org.springframework.data:spring-data-jpa:jar:1.11.10.RELEASE:compile
O] |  |  +- org.springframework.data:spring-data-commons:jar:1.13.10.RELEASE:compile
O] |  |  +- org.springframework:spring-orm:jar:4.3.14.RELEASE:compile
O] |  |  +- org.springframework:spring-context:jar:4.3.14.RELEASE:compile
O] |  |  +- org.springframework:spring-tx:jar:4.3.14.RELEASE:compile
O] |  |  +- org.springframework:spring-beans:jar:4.3.14.RELEASE:compile
O] |  |  +- org.slf4j:slf4j-api:jar:1.7.25:compile
O] |  |  \- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
O] |  \- org.springframework:spring-aspects:jar:4.3.14.RELEASE:compile
O] +- org.springframework.boot:spring-boot-starter-web:jar:1.5.10.RELEASE:compile
O] |  +- org.springframework.boot:spring-boot-starter-Tomcat:jar:1.5.10.RELEASE:compile
O] |  |  +- org.Apache.Tomcat.embed:Tomcat-embed-core:jar:8.5.27:compile
O] |  |  |  \- org.Apache.Tomcat:tomcat-annotations-api:jar:8.5.27:compile
O] |  |  +- org.Apache.Tomcat.embed:Tomcat-embed-el:jar:8.5.27:compile
O] |  |  \- org.Apache.Tomcat.embed:Tomcat-embed-websocket:jar:8.5.27:compile
O] |  +- org.hibernate:hibernate-validator:jar:5.3.6.Final:compile
O] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
O] |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
O] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile
O] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
O] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile
O] |  +- org.springframework:spring-web:jar:4.3.14.RELEASE:compile
O] |  \- org.springframework:spring-webmvc:jar:4.3.14.RELEASE:compile
O] |     \- org.springframework:spring-expression:jar:4.3.14.RELEASE:compile
O] +- com.amazonaws:aws-Java-sdk-s3:jar:1.11.288:compile
O] |  +- com.amazonaws:aws-Java-sdk-kms:jar:1.11.125:compile
O] |  +- com.amazonaws:aws-Java-sdk-core:jar:1.11.125:compile
O] |  |  +- commons-logging:commons-logging:jar:1.1.3:compile
O] |  |  +- org.Apache.httpcomponents:httpclient:jar:4.5.5:compile
O] |  |  |  +- org.Apache.httpcomponents:httpcore:jar:4.4.9:compile
O] |  |  |  \- commons-codec:commons-codec:jar:1.10:compile
O] |  |  +- software.Amazon.ion:ion-Java:jar:1.0.2:compile
O] |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.8.10:compile
O] |  |  \- joda-time:joda-time:jar:2.9.9:compile
O] |  \- com.amazonaws:jmespath-Java:jar:1.11.125:compile
O] +- com.h2database:h2:jar:1.4.196:runtime
O] +- org.projectlombok:lombok:jar:1.16.20:compile
O] \- org.springframework.boot:spring-boot-starter-test:jar:1.5.10.RELEASE:test
O]    +- org.springframework.boot:spring-boot-test:jar:1.5.10.RELEASE:test
O]    +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.10.RELEASE:test
O]    +- com.jayway.jsonpath:json-path:jar:2.2.0:test
O]    |  \- net.minidev:json-smart:jar:2.2.1:test
O]    |     \- net.minidev:accessors-smart:jar:1.1:test
O]    |        \- org.ow2.asm:asm:jar:5.0.3:test
O]    +- junit:junit:jar:4.12:test
O]    +- org.assertj:assertj-core:jar:2.6.0:test
O]    +- org.mockito:mockito-core:jar:1.10.19:test
O]    |  \- org.objenesis:objenesis:jar:2.1:test
O]    +- org.hamcrest:hamcrest-core:jar:1.3:test
O]    +- org.hamcrest:hamcrest-library:jar:1.3:test
O]    +- org.skyscreamer:jsonassert:jar:1.4.0:test
O]    |  \- com.vaadin.external.google:Android-json:jar:0.0.20131108.vaadin1:test
O]    +- org.springframework:spring-core:jar:4.3.14.RELEASE:compile
O]    \- org.springframework:spring-test:jar:4.3.14.RELEASE:test
O] ------------------------------------------------------------------------

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>com.example</groupId>
    <artifactId>AwsSdkDemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>AwsSdkDemo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <Java.version>1.8</Java.version>
        <spring-cloud.version>Edgware.SR2</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-Java-sdk-s3</artifactId>
            <version>1.11.288</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-Java-sdk-core</artifactId>
            <version>1.11.288</version>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>
5
user3444718

みなさん、ありがとうございました。問題は、春に引っ張られるaws-core依存関係のバージョンが一貫していないことでした。コアバージョン(1.11.288)を手動で指定すると、問題が解決します。前述のように、Spring Bootのpomにバージョンを明示的に配置しない場合でも、この問題を解決できます。

6
user3444718

私は同様の問題に遭遇しましたcom.amazonaws:aws-Java-sdk-secretsmanager:jar:1.11.430com.amazonaws:aws-Java-sdk-core:jar:1.11.125 pomにcore-sdk jarを具体的に含めることで、これを解決します。

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-Java-sdk-core</artifactId>
    <version>1.11.430</version>
</dependency>

また、aws-Java-sdkに対して問題を開きました: https://github.com/aws/aws-sdk-Java/issues/1787

4
aheffernan