Spring Boot - Spring Cloud AWS:找不到区域 [英] Spring Boot - Spring Cloud AWS : region not found

查看:58
本文介绍了Spring Boot - Spring Cloud AWS:找不到区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Spring Boot、Spring Cloud AWS 服务,用于从 AWS SQS 队列接收消息.在我自己的个人 AWS 账户服务中一切正常,区域设置为us-east-1",但是当切换到 AWS GovCloud 区域us-gov-east-1"时,收到错误消息The区域us-gov-east-1"不是有效区域".追踪与提取真正旧版本的 aws-java-sdk-core-1.11.415 库相关的问题,该库的 Regions.enum 对象中不包含新的 GovCloud 区域.不太确定为什么这个项目会引入 aws-java-sdk-core-1.11.415 的一个非常古老的传递依赖项,因为我相信 Spring-Cloud 项目将引入 aws-java-sdk-core-1.11.7xx.当然,我可能在 pom.xml 配置中做错了什么,但我似乎无法弄清楚为什么该项目引入了旧版本的 aws-java-sdk-core 库.

I have a Spring Boot, Spring Cloud AWS service, written to receive messages from an AWS SQS queue. Everything has been working fine within my own personal AWS account services with region set to "us-east-1", but when switching over to AWS GovCloud region "us-gov-east-1", receiving error message "The region 'us-gov-east-1' is not a valid region". Tracked down the problem to be related to pulling a real old version of the aws-java-sdk-core-1.11.415 library that does not contain the new GovCloud region within its Regions.enum object. Not really sure why this project is pulling in a very old transitive dependency of aws-java-sdk-core-1.11.415, as I believe the Spring-Cloud project is set to pull in aws-java-sdk-core-1.11.7xx. Granted, I may have done something wrong in my pom.xml configuration, but I can't seem to figure out why the project is pulling in an old old version of the aws-java-sdk-core library.

我一直在进行初始测试,我的默认区域设置为没有问题:

I have been running for intial testing purposes with my default region set to with no problems:

cloud.aws.region.static=us-east-2

但是,我们正在尝试将我们的 Docker 容器服务迁移到新的 AWS GovCloud 区域:

However, we are trying to migrate our Docker container service over to the new AWS GovCloud region:

cloud.aws.region.static=us-gov-east-1

我在运行时收到以下错误:

I am getting the following error during runtime:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.region.StaticRegionProvider]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: The region 'us-gov-east-1' is not a valid region!
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:217) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:117) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:310) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
... 78 common frames omitted
Caused by: java.lang.IllegalArgumentException: The region 'us-gov-east-1' is not a valid region!
at org.springframework.cloud.aws.core.region.StaticRegionProvider.<init>(StaticRegionProvider.java:47) ~[spring-cloud-aws-core-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:204) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
... 80 common frames omitted
Caused by: java.lang.IllegalArgumentException: Cannot create enum from us-gov-east-1 value!
at com.amazonaws.regions.Regions.fromName(Regions.java:87) ~[aws-java-sdk-core-1.11.415.jar!/:na]
at org.springframework.cloud.aws.core.region.StaticRegionProvider.<init>(StaticRegionProvider.java:44) ~[spring-cloud-aws-core-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
... 85 common frames omitted

pom.xml 配置文件如下:

pom.xml configuration file is as follows:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.foo.scout</groupId>
<artifactId>scout-s3-sqs</artifactId>
<version>0.0.3</version>

<name>scout-s3-sqs</name>
<description>Scout S3</description>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>11</java.version>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>

    <docker.image.prefix>foo</docker.image.prefix>
    <spring-cloud.version>Hoxton.SR5</spring-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-aws</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-aws-messaging</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.kafka</groupId>
        <artifactId>spring-kafka</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>

    <!-- AWS uses JODA DateTime objects -->
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.10.6</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jsr310</artifactId>
    </dependency>

    <!-- Testing Dependencies -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.kafka</groupId>
        <artifactId>spring-kafka-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>

        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>dockerfile-maven-plugin</artifactId>
            <version>1.4.13</version>
            <configuration>
                <repository>${docker.image.prefix}/${project.artifactId}</repository>
                <tag>${project.version}</tag>
                <buildArgs>
                    <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
                </buildArgs>
                <pullNewerImage>false</pullNewerImage>
            </configuration>
        </plugin>
    </plugins>
</build>

感谢任何和所有帮助.

推荐答案

要追踪旧版本的 AWS Java SDK 在您的代码中泄漏的位置,请执行 mvn dependency:tree.研究树 看看它来自哪里.

To track down where did the old version of AWS Java SDK leaked in your code execute mvn dependency:tree. Study the tree and look where it comes from.

要强制使用最新版本的 AWS Java SDK,请将其 BOM 导入您的 dependenciesManagement:

To force the latest version of AWS Java SDK, import its BOM to your dependenciesManagement:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-bom</artifactId>
            <version>1.11.808</version>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

官方文档 和这个 SO 线程.

这篇关于Spring Boot - Spring Cloud AWS:找不到区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆