Spring云配置服务器.属性中的环境变量

ykr*_*nko 6 spring spring-cloud-config

我像这样配置了Spring Cloud Config服务器:

@SpringBootApplication
@EnableAutoConfiguration
@EnableConfigServer
public class ConfigServer {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServer.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用"原生"配置文件,因此从文件系统中获取属性:

server.port=8888
spring.profiles.active=native
spring.cloud.config.server.native.search-locations: classpath:/global
Run Code Online (Sandbox Code Playgroud)

现在棘手的部分是一些属性包含环境变量.'global/application-production.properties'中的属性配置如下:

test=${DOCKER_HOST}
Run Code Online (Sandbox Code Playgroud)

当我启动Config Server时 - 一切正常.但是,当我访问http:// localhost:8888/testapp/production时,我看到:

{
    name: "testapp",
    profiles: [
        "production"
],
    label: null,
    version: null,
    propertySources: [
        {
            name: "classpath:/global/application-production.properties",
            source: {
                test: "${DOCKER_HOST}"
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

所以来自ENV变量的值并没有取代$ {DOCKER_HOST} put而是按原样返回.

但是如果我访问http:// localhost:8888/application-production.properties,那么结果是非JSON而是纯文本:

test: tcp://192.168.99.100:2376
Run Code Online (Sandbox Code Playgroud)

Spring文档说:

YAML和属性表示有一个额外的标志(作为布尔查询参数resolvePlaceholders提供),用于表示源文档中的占位符(在标准的Spring $ {...}表单中)应该在呈现之前尽可能在输出中解析.对于不了解Spring占位符约定的消费者而言,这是一个有用的功能.

由于某些原因,resolvePlaceholders不适用于JSON表示,因此服务器配置客户端需要知道在服务器上配置的所有ENV变量.

是否可以像纯文本(属性)表示一样强制JSON表示resolvePlaceholders?

Nas*_*ova 2

我遇到了同样的问题。查看 Spring Cloud Config Repository 后,我发现了以下提交: Omit system properties and env vars from placeholders in config

看起来这种行为不受支持。