【问题标题】:Spring Config Server - resolvePlaceholders + enviroment variablesSpring Config Server - 解析占位符+环境变量
【发布时间】:2018-08-14 08:38:19
【问题描述】:

我有关于在配置服务器的共享文件中解析环境变量的问题。 我目前的设置非常小:

  1. src/main/resources/shared/application.yml

    应用: 版本:0.0.1-早期 测试:${JAVA_HOME}

  2. src/main/resources/application.properties

    spring.profiles.active=native spring.cloud.config.server.native.searchLocations=classpath:/shared

  3. 使用 gradle :

    • spring-boot-gradle-plugin:2.0.0.RELEASE
    • spring-cloud-dependencies:Camden.SR7
    • 然后当然在 deps 中编译 'org.springframework.cloud:spring-cloud-config-server'

问题: GET http://localhost:8888/apptest/application 给我:

{
    "name": "apptest",
    "profiles": [
        "application"
    ],
    "label": null,
    "version": null,
    "state": null,
    "propertySources": [
        {
            "name": "classpath:/shared/application.yml",
            "source": {
                "application.version": "0.0.1-early",
                "application.test": "${JAVA_HOME}"
            }
        }
    ]
}

所以 env 变量没有被解析。同样的事情是:

我查看了Spring cloud config server. Environment variables in properties,但解决方案对我没有帮助 + 从那时起那里很少有新版本。所以我要提出新问题。

【问题讨论】:

    标签: java spring-cloud spring-cloud-config spring-config


    【解决方案1】:

    这里发生的变化https://github.com/spring-cloud/spring-cloud-config/commit/f8fc4e19375d3b4c0c2562a71bc49ba288197100 删除了对替换环境变量的支持。

    您始终可以添加新控制器并覆盖 EnvironmentPropertySource#prepareEnvironment 的行为

    【讨论】:

      【解决方案2】:

      实际上这不是错误,一切都很好。我不明白配置服务器是如何工作的。

      1. http://localhost:8888/apptest/application - 返回尚未解析的 ${JAVA_HOME} 的值
      2. 当我们得到 ei。进入容器 "C" ping 配置服务以进行配置并执行 curl http://config:8888/apptest/application 我们得到相同的结果 - 未解决 ${JAVA_HOME}
      3. 但是当我们查看 Spring 应用程序 ei 时。在容器“C”中并尝试在某处注入@Value("${application.test}"),我们得到正确的值或未设置环境变量的信息。

      表示环境变量在客户端解析。
      多亏了这一点,我才明白 env_variables 方法是如何不生产就绪的。

      【讨论】:

        猜你喜欢
        • 2019-01-12
        • 2016-07-24
        • 2017-05-01
        • 2020-10-05
        • 2017-08-17
        • 2016-10-22
        • 2016-09-15
        • 2019-03-16
        • 1970-01-01
        相关资源
        最近更新 更多