springBootVersion = '2.0.0.M7' springCloudVersion = 'Finchley.M5'

docker-compose setup (stripped down):

mongo:
  ports:
      - 27017:27017
eureka:
  ports:
      - 8761:8761
test-client:
  ports:
      - 8080:8080
  environment:
      SPRING_DATA_MONGODB_HOST: "mongo"
      EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: "http://eureka:8761/eureka/"

The EUREKA_CLIENT_SERVICEURL_DEFAULTZONE environment variable is not picked up. Others, like the mongo host work ok.

Moving the setting inside the test-client application.properties works: eureka.client.service-url.defaultZone=http://eureka:8761/eureka/

I think it might be something caused by the naming of defaultZone (the service-url binds to a Map and I don't think the rezolver handles correctly the camelCase in defaultZone)

Probably related to https://github.com/spring-projects/spring-boot/issues/8902

Comment From: ryanjbaxter

Possibly related. I dont think we need to keep this issue open though if it is a Boot issue.

Comment From: bobpiece

Any update on this topic?

Comment From: danmana

I haven't seen any updates on this.

The fix in spring-projects/spring-boot#8902 turns all keys bound to maps into lowercase (only if binding from env variables).

So in this case the EurekaClientConfigBean.serviceUrl map will contain the environment variable at the key "defaultzone", but the bean tries to read it using "defaultZone", so it doesn't find it.

I guess one way to fix this is to change the key to lowercase only DEFAULT_ZONE = "defaultzone". The downside is that all existing yaml/property file examples will not work anymore (I think). Or perhaps use a CaseInsensitiveMap :)

Alternatively you could try to use the export SPRING_APPLICATION_JSON='{"com.test": {"property":{"foo": {"bar" : "value"} } } ~~hack~~ setting.

Comment From: spencergibb

I don't think we're going to change the key, as you mentioned, this will break existing compatiblity. SPRING_APPLICATION_JSON is not a hack.

Comment From: danmana

True, SPRING_APPLICATION_JSON is not a hack, but it sucks that we can't use env variables to set this specific property, while others work ... lost a lot of time debugging this.

Also in the ordering of config sources SPRING_APPLICATION_JSON is loaded 5th, and env variables are loaded 10th, so there might be cases when using the json will not work (gets overriden).

Perhaps we can target the key change for the next major release, when it would be ok to introduce breaking changes.

Comment From: Hronom

So what the status of this? Why this property not parsed by using spring boot configuration mechanic https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config

What the workaround if we need to set it in environment variable?

Comment From: Hronom

Ok, guys here is the workaround for this, this is my eureka-service.properties:

management.security.enabled=false
management.info.git.mode=full

eureka.client.region=default
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true

# https://github.com/spring-cloud/spring-cloud-netflix/issues/2541
eureka.client.service-url.defaultZone=${SERVICE_URL_DEFAULT_ZONE}

And then I'm able set eureka.client.service-url.defaultZone through environment variable SERVICE_URL_DEFAULT_ZONE.

Looks creepy, but it works!

Comment From: spencergibb

Closing as answered.

Comment From: Hronom

@spencergibb the proposed solution is temporary workaround, it's not a solution for initial problem.

Comment From: spencergibb

This is a limitation of maps and keys in spring boot external configuration. There's nothing to do on our end.

Comment From: 1eam

Another use case: A properties.yml-file could also be used to set this property:

eureka:
  client:
    serviceUrl:
      defaultZone: ${EUREKA_URI:http://localhost:8010/eureka}
  instance:
    preferIpAddress: true