Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msievers/22bfa856f20cf1e854dd025f093f469f to your computer and use it in GitHub Desktop.
Save msievers/22bfa856f20cf1e854dd025f093f469f to your computer and use it in GitHub Desktop.
[Spring Cloud, Zookeeper, Configuration] Setup Zookeeper configuration with Spring Boot and Spring Cloud

Motivation

With latest release of Spring Cloud 2020.0 (aka Ilford) it's now easier than ever to setup Zookeeper configuration support, but the official documentation currnently lacks some straight-forward example.

Solution

Add the spring-cloud-dependencies bom to the dependencyManagement section of you pom.xml

<dependencyManagement>
    <dependencies>
        <!-- ... -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>2020.0.2</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- ... -->
    </dependencies>
</dependencyManagement>

Add the spring-cloud-starter-zookeeper-config to your applications dependencies

<dependencies>
    <!-- ... -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-zookeeper-config</artifactId>
    </dependency>
    <!-- ... -->
</dependencies>

Setup the necessary settings in your application.properties

spring.cloud.zookeeper.connect-string=your.zookeeper.location:2181
spring.cloud.zookeeper.config.root=some/config/root
spring.cloud.zookeeper.config.defaultContext=common
spring.cloud.zookeeper.config.name=my-application
spring.config.import=zookeeper:

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment