客户端特定配置的占位符解析

Placeholders resolution for client specific configuration

我正在学习 Spring Cloud Config 项目能力。我想知道是否可以将占位符用于特定于应用程序的配置?

例如:

我的 application.yml 文件:

server:
  port: 8888

spring:
  profiles:
    active: native
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/config

config 文件夹包含一个 my-app.yml 文件:

key:
  value: ${my.password}

服务器以 -Dmy.password=password 环境变量启动。对 /my-app/native url returns:

的获取请求
{
    "name": "my-app",
    "profiles": ["native"],
    "label": null,
    "version": null,
    "state": null,
    "propertySources": [{
        "name": "classpath:/config/my-app.yml",
        "source": {
            "key.value": "${my.password}"
        }
    }]
}

placeholder 中的 env 属性 未经评估返回给客户端,有没有办法在将响应发送给客户端之前评估 属性?

您可以使用 override 功能在启动服务器时设置 key.value 的值:

-Dspring.cloud.config.server.overrides.key.value=overrideValue

认为你的客户端必须在之后启动。

Spring documentation:

Property Overrides

The Config Server has an “overrides” feature that lets the operator provide configuration properties to all applications. The overridden properties cannot be accidentally changed by the application with the normal Spring Boot hooks. To declare overrides, add a map of name-value pairs to spring.cloud.config.server.overrides, as shown in the following example:

spring:   
  cloud:
    config:
      server:
        overrides:
          foo: bar 

The preceding examples causes all applications that are config clients to read foo=bar, independent of their own configuration.

...