Search code examples
javaspringconfigurationspring-config

How to dynamically generate a configuration property in spring configuration server?


I want my spring configuration server to return a property that is based upon client specific details.

Specifically, in some profiles, I want the value of a property named 'self.url' to include the client's ip. In other profiles it's a constant value property...

Is it possible? And if so, how?

Thanks a lot guys


Solution

  • Well, I do think you can set different values of properties for different profiles.

    I don't think it is possible out of the box to have a placeholder like self.url resolved by the config server into the requesting config client's IP address. Keep in mind that the config server is a server hosting files and serving them up in response to requests. It would be unusual to transform the files in a way specific to the requester before returning them. And it would have to be a per-requester transformation from the config server's perspective as there could be multiple instances running for a particular app (so multiple clients of the same config file, each with a different IP). I don't know of a feature in the config server to do this. (It looks to me that it can resolve placeholders locally but only internally to the config server, otherwise the placeholder is passed on to the requesting client itself to resolve.)

    Perhaps you could have the properties file for that profile contain a placeholder and have the client itself resolve that into its own IP address using java. (An example here or here.)

    It's also possible to set defaults in the config in the config server that individual clients can override. That could perhaps be applicable to your case.