spring - Spring Boot 无法解析 aws 参数存储变量
问题描述
我正在尝试将秘密保护到 Spring Cloud 中。我有来自 Spring Cloud 的微服务读取配置,但无法从参数存储中解析值。例如安全数据库用户并通过。
password=${/config/password} 但路径未解析
我添加了 Maven 依赖项
spring-cloud-starter-aws-参数-存储-配置
欢迎任何想法
解决方案
也许您缺少 boostrap.yaml 文件?它应该在您的/src/main/resources/
文件夹中,看起来像这样:
aws:
paramstore:
name: your-application-name
default-context: application
profile-separator: _
此外,我认为默认查找路径是/config/application
您可能希望将参数放在/config/application/password
. 由于它可能特定于应用程序,因此您可能希望这样做/config/your-application-name_${environmentName}
您还需要正确设置 Spring Cloud 依赖项。我在 Gradle 文件中有我的。这是我的整个 Gradle 文件供您参考。
buildscript {
ext {
springBootVersion = '2.0.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'idea'
apply plugin: 'groovy'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
springBoot {
mainClassName 'com.myapi.Application'
}
group = 'com.myapi'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
jar {
baseName = 'my-api'
version = 1.0
}
repositories {
mavenCentral()
}
ext {
springCloudVersion = 'Finchley.RELEASE'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
dependencies {
implementation "org.springframework.boot:spring-boot-starter-security:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
//AWS Param store configuration
implementation 'com.amazonaws:aws-java-sdk-core:1.11.477'
implementation 'org.springframework.cloud:spring-cloud-starter-aws-parameter-store-config'
implementation 'com.amazonaws:aws-java-sdk-ssm:1.11.475'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-aws-messaging:2.0.1.RELEASE' //AWS SNS configuration
implementation 'org.springframework.boot:spring-boot-configuration-processor' //Necessary for the @ConfigurationProperties tag
implementation 'org.springframework.cloud:spring-cloud-aws-autoconfigure:2.0.1.RELEASE' //Necessary for auto wiring AmazonSNS
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.codehaus.groovy:groovy-all:2.4.15'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.github.derjust:spring-data-dynamodb:5.0.4'
//Swagger
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.spockframework:spock-core:1.1-groovy-2.4'
testImplementation 'org.jsoup:jsoup:1.12.1'
}
推荐阅读
- java - 如何让2个线程共享数据?(爪哇)
- pyspark - 使用 Python 在 Databricks 中使用 XGBoost
- css - 可滚动的 Ionic 4 选项卡
- c++ - 创建 alignas(64) 整数的向量
- html - 如何使用 Angular js 创建带有选择和非选择复选框的下拉框,就像在下图中一样?
- python-3.x - 我的 GET 请求的状态码 400 - Mixpanel API
- imagemagick - ImageMagick - %d 可以与图像属性百分比转义一起使用吗?
- ios - AVFoundation 位置音频在 iOS 设备上不起作用
- javascript - 如何在多步表单上屏蔽输入
- javascript - HTML - document.write