0
votes

I've got question about resolving environment variables in shared files of config server. My current setup is pretty minimal :

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

    application: version: 0.0.1-early test: ${JAVA_HOME}

  2. src/main/resources/application.properties :

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

  3. Using gradle with :

    • spring-boot-gradle-plugin:2.0.0.RELEASE
    • spring-cloud-dependencies:Camden.SR7
    • And then of course compile 'org.springframework.cloud:spring-cloud-config-server' in deps

Problem : GET http://localhost:8888/apptest/application gives me :

{
    "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}"
            }
        }
    ]
}

So env variable is not resolved. Same thing is with :

I've looked at Spring cloud config server. Environment variables in properties but solution didn't help me + there where few new versions since then. So I'm opening new question.

2

2 Answers

1
votes

Actually it's not a bug and everything is fine. I did not understood how Config server works.

  1. http://localhost:8888/apptest/application - returns yet not resolved value of ${JAVA_HOME}
  2. When we get ei. into container "C" that pings Config Service for configuration and do curl http://config:8888/apptest/application we get the same - unresolved ${JAVA_HOME}
  3. But when we look into Spring application ei. in container "C" and try to inject @Value("${application.test}") somewhere, we get proper value or info that env variable was not set.

It means that environment variables are resolved on client side.
Thanks to that I've understood how NOT production ready env_variables approach is.

0
votes

Well the changes happened here https://github.com/spring-cloud/spring-cloud-config/commit/f8fc4e19375d3b4c0c2562a71bc49ba288197100 that removes the support of replacing the environment variables.

You can always add a new controller and override the behaviour of the EnvironmentPropertySource#prepareEnvironment