创建 AWS 应用程序时缺少 AWS 属性
Missing AWS properties when creating AWS application
我正在努力弄清楚如何将 AWS 属性添加到我的 application.properties(或 application.yml)文件中,而且我不确定我在 STS 中的设置不正确。
我可以使用 Spring Initializr 重现此创建一个简单的 AWS 应用程序。我正在添加 AWS、Consul 和 REST,因为这是真正的应用程序正在使用的。这是它生成的 POM。
<?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>edu.dkist</groupId>
<artifactId>staging-service-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>staging-service-demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.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>Dalston.SR4</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</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>
我没有向此示例的应用程序添加任何代码,只添加了生成的代码。这是一个测试,看看我正在使用的应用程序是否有问题。当我尝试添加应用程序 属性 时,AWS 没有任何显示。如果我创建一个 YAML 文件也是如此。
如果我强制这个问题,无论如何添加它 STS 说 属性 未知。
编译应用程序抛出异常:
Caused by: java.lang.IllegalStateException: There is not EC2 meta data available, because the application is not running in the EC2 environment. Region detection is only possible if the application is running on a EC2 instance
该应用程序不在 EC2 实例上 运行,它在本地 运行。从我读过的内容来看,如果 aws.region.auto 在 EC2 上不是 运行,我需要添加它,但我无法让应用程序确认 属性 存在。访问密钥和秘密密钥也是如此。
所以...经过大量修改和阅读其他帖子后,如果您添加这些属性,它们似乎会起作用,即使 STS 无法识别它们也是如此。
我加了
cloud:
aws:
credentials:
instanceProfile: false
region:
static: eu-west-1
stack:
auto: false
程序将 运行。
让我感到困惑的另一件事是属性路径的不一致。例如,Consul 属性位于
spring.cloud.consul.*
AWS 在
cloud.aws.*
没有 "spring" 启动 AWS 属性。我确定存在不一致的原因,我只是不知道。
我正在努力弄清楚如何将 AWS 属性添加到我的 application.properties(或 application.yml)文件中,而且我不确定我在 STS 中的设置不正确。
我可以使用 Spring Initializr 重现此创建一个简单的 AWS 应用程序。我正在添加 AWS、Consul 和 REST,因为这是真正的应用程序正在使用的。这是它生成的 POM。
<?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>edu.dkist</groupId>
<artifactId>staging-service-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>staging-service-demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.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>Dalston.SR4</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</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>
我没有向此示例的应用程序添加任何代码,只添加了生成的代码。这是一个测试,看看我正在使用的应用程序是否有问题。当我尝试添加应用程序 属性 时,AWS 没有任何显示。如果我创建一个 YAML 文件也是如此。
如果我强制这个问题,无论如何添加它 STS 说 属性 未知。
编译应用程序抛出异常:
Caused by: java.lang.IllegalStateException: There is not EC2 meta data available, because the application is not running in the EC2 environment. Region detection is only possible if the application is running on a EC2 instance
该应用程序不在 EC2 实例上 运行,它在本地 运行。从我读过的内容来看,如果 aws.region.auto 在 EC2 上不是 运行,我需要添加它,但我无法让应用程序确认 属性 存在。访问密钥和秘密密钥也是如此。
所以...经过大量修改和阅读其他帖子后,如果您添加这些属性,它们似乎会起作用,即使 STS 无法识别它们也是如此。
我加了
cloud:
aws:
credentials:
instanceProfile: false
region:
static: eu-west-1
stack:
auto: false
程序将 运行。
让我感到困惑的另一件事是属性路径的不一致。例如,Consul 属性位于
spring.cloud.consul.*
AWS 在
cloud.aws.*
没有 "spring" 启动 AWS 属性。我确定存在不一致的原因,我只是不知道。