Spring 客户端特定配置的占位符解析
我正在学习项目能力。我想知道是否可以为特定于应用程序的配置使用占位符 例如: My application.yml文件:Spring 客户端特定配置的占位符解析,spring,spring-boot,spring-cloud,spring-cloud-config,Spring,Spring Boot,Spring Cloud,Spring Cloud Config,我正在学习项目能力。我想知道是否可以为特定于应用程序的配置使用占位符 例如: My application.yml文件: server: port: 8888 spring: profiles: active: native cloud: config: server: native: search-locations: classpath:/config key: value: ${my.password}
server:
port: 8888
spring:
profiles:
active: native
cloud:
config:
server:
native:
search-locations: classpath:/config
key:
value: ${my.password}
config文件夹包含一个my-app.yml文件:
server:
port: 8888
spring:
profiles:
active: native
cloud:
config:
server:
native:
search-locations: classpath:/config
key:
value: ${my.password}
服务器以-Dmy.password=password环境变量启动。对/my app/native url的get请求返回:
{
"name": "my-app",
"profiles": ["native"],
"label": null,
"version": null,
"state": null,
"propertySources": [{
"name": "classpath:/config/my-app.yml",
"source": {
"key.value": "${my.password}"
}
}]
}
占位符中的env属性未经计算就返回到客户端,是否有方法在将响应发送到客户端之前计算该属性 启动服务器时,您可以使用
覆盖
功能设置键值
的值:
-Dspring.cloud.config.server.overrides.key.value=overrideValue
我认为你的客户必须在事后开始
:
属性覆盖
配置服务器具有“覆盖”功能,允许操作员向所有应用程序提供配置属性。使用普通Spring引导挂钩的应用程序不能意外更改重写的属性。要声明覆盖,请将名称-值对映射添加到spring.cloud.config.server.overrides
,如下例所示:
spring:
cloud:
config:
server:
overrides:
foo: bar
前面的示例导致所有配置客户端应用程序读取foo=bar
,而不依赖于它们自己的配置
谢谢你的回答,这是我的问题。例如,如果配置服务器为不同的应用程序提供不同的值(相同的键)。一个值取自环境,而另一个值硬编码在配置文件中。有控制它的选择吗?我认为这是不可能的(至少我不知道)。你的密码经常更改吗?为什么不在服务器GIT中使用spring引导云{cipher}。每个客户端都有一个{cipher}(按applicationName或不同的标签组织)?你会有加密密码的好处。那适合你的需要吗?如果你不知道密码,让我知道,我会更新我熟悉的密码功能的答案。问题是,密码可能在安装过程中或根据要求更改。然后,我不知道还能做些什么(不是说没有什么,只是我不知道)。