Search code examples
javaspring-bootspring-cloud-config

Using environment based configuration properties in java library


I have one java spring boot library and it is using some configuration as below using zookeeper address for loadbalancer.

<user:registry regProtocol="zookeeper" name="testZk" address="${zookeeper.address}"/>

zookeeper.address will be different between development and production environments.

Users of this library can include zookeeper.address in their cloud config properties based on the environment but are there other ways so that library users don't need to include these in their properties and library in some way use different properties based on environment from user.


Solution

  • Serving Plain Text will resolve above problem.

    http://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.0.0.M5/single/spring-cloud-config.html#_serving_plain_text

    Just define multiple environments, you wish to in application properties and on the user side activate the properties, it will work.