问题描述
我正在尝试从连接到两个源的配置服务器获取我的微服务配置:git和Vault(用于秘密)。我有下面的配置: 在配置服务器中:@H_502_1@
server:
port: 8888
spring:
profiles:
active: git,vault
cloud:
config:
server:
vault:
port: 8200
host: 127.0.0.1
kvVersion: 2
git:
order: 2
uri: [email protected]
并在bootstrap.yml的客户端中:@H_502_1@
spring:
application:
name: my-service-name
cloud:
config:
uri: http://localhost:8888
token: //token
label: dev
但是在我的保险库中,我的路径是这样的:@H_502_1@
secret/cad
|--my-service-name
当我直接在/secret/my-service-name
中创建秘密时,我可以访问我的秘密,但是如何在/secret/cad/my-service-name
@H_502_1@中配置对秘密的访问权限
谢谢。@H_502_1@
解决方法
您可以创建实现VaultConfigurer的自定义配置类,在其中可以覆盖自定义路径
@配置 公共类CustomVaultConfiguraton实现VaultConfigurer {
@override
public void addSecretsBackends(SecretBackendConfigurer configures){
configures.add("customPath");
} }
在spring.factories中添加上述配置类 org.springframework.cloud.bootstrap.BootstrapConfiguration = \ packagename.CustomVaultConfiguration