Search code examples
javaspring-bootspring-integrationspring-cloud-zookeeper

Not able to execute the code for ZooKeeperMetaDataStore


I am using spring integration where I am trying to create a bean for MetaData

    @Bean
    public MetadataStore zkStore(CuratorFramework client) {
        return new ZookeeperMetadataStore(client);
    }

I am getting the error

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'zkStore'; nested exception is java.lang.NoSuchMethodError: 'org.apache.curator.framework.listen.ListenerContainer org.apache.curator.framework.recipes.cache.PathChildrenCache.getListenable()'

After dig down further I found class PathChildrenCache is deprecated and replaced by Interface. Is there any way I can run this piece of code.

dependencies used by project

 <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zookeeper-config</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.curator</groupId>
                    <artifactId>curator-recipes</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-zookeeper</artifactId>
            <version>5.5.2</version>
        </dependency>

Solution

  • The java.lang.NoSuchMethodError means that you have incompatible classpath.

    Spring Integration is based on the Curator 4.3.0. So, better to revise your dependencies in whatever would make it working.

    We have an opened issue to move to Curator 5.1 (or higher), but since there are enough breaking changes with their new API, we can't do that immediately: https://github.com/spring-projects/spring-integration/issues/3435