Google Secret Manager 机密未加载到应用程序属性中 - Spring Boot - App Engine

2 spring-boot google-secret-manager

我在 App Engine 上部署了一个 Spring Boot 项目(war)

应用程序属性

mysecret=${sm://projects/48***1430/secrets/order-db-password}
Run Code Online (Sandbox Code Playgroud)

在控制器中,我使用值注释

@Value("${mysecret}")
private String myAppSecret;
Run Code Online (Sandbox Code Playgroud)

日志正在打印 -

“myAppSecret = //projects/48***1430/secrets/order-db-password”

构建.gradle

 implementation 'org.springframework.cloud:spring-cloud-gcp-starter-secretmanager:1.2.2.RELEASE'
Run Code Online (Sandbox Code Playgroud)

权限似乎没问题

myapplication@appspot.gserviceaccount.com is Secret manager admin
Run Code Online (Sandbox Code Playgroud)

我怎样才能识别问题?

小智 6

我需要 3 处改变

i)bootstrap.properties

spring.cloud.gcp.secretmanager.enabled=true
spring.cloud.gcp.secretmanager.bootstrap.enabled=true
Run Code Online (Sandbox Code Playgroud)

ii)dependency - 否则不会查看 bootstrap.props

implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
Run Code Online (Sandbox Code Playgroud)

对于秘密经理

implementation 'com.google.cloud:spring-cloud-gcp-starter-secretmanager'
Run Code Online (Sandbox Code Playgroud)

iii)使用秘密 - 长或短,但我使用完整格式

spring.datasource.password=${sm://projects/4#6##4#0/secrets/dbencpwd}
Run Code Online (Sandbox Code Playgroud)