【发布时间】:2021-07-30 22:20:26
【问题描述】:
我创建了一个 Spring Boot 应用程序,我想在其中将 AWS 机密用于 application.properties。我正在使用 spring boot 2.2.6.RELEASE 并且根据文档,我在我的 pom 中添加了以下依赖项:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
<version>2.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws-secrets-manager-config</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
从 AWS Secrets Manager 服务中,我创建了一个“其他类型的秘密”类型的新秘密,并为其命名/secret/myservice。为了测试,我添加了一个密钥作为 environment 和值作为 aws 我想在我的控制器中检索。我不清楚的部分是我需要在 bootstrap.yml 文件中创建的条目,因为我对Spring Cloud AWS documentation. 中的说明感到困惑,有人可以提供一些正确的说明,因为我无法正确使用此功能。作为参考,我在 bootstrap.yml 文件中添加了这个:
aws:
secretsmanager:
name: myservice
prefix: /secret
enabled: true
defaultContext: application
failFast: true
cloud:
aws:
region:
static: us-east-1
并尝试在控制器中检索环境值:
@RestController
@EnableWebMvc
public class PingController {
@Value(value = "${environment}")
private String environment;
@RequestMapping(path = "/ping", method = RequestMethod.GET)
public Map<String, String> ping() {
Map<String, String> pong = new HashMap<>();
pong.put("pong", "Hello, World!" + "This is " + environment + " environment...");
return pong;
}
}
【问题讨论】:
-
你能解决这个问题吗?
-
你解决了吗?
-
@sar 检查答案
标签: java spring amazon-web-services spring-boot aws-secrets-manager