0

我正在使用 spring 集成,我正在尝试为 MetaData 创建一个 bean

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

我收到错误

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()'

进一步挖掘后,我发现类 PathChildrenCache 已被弃用并被接口取代。有什么办法可以运行这段代码。

项目使用的依赖项

 <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>
4

1 回答 1

1

java.lang.NoSuchMethodError意味着您的类路径不兼容。

Spring Integration 基于 Curator 4.3.0。因此,最好修改您的依赖项以使其正常工作。

我们有一个未解决的问题要转移到 Curator 5.1(或更高版本),但由于他们的新 API 有足够多的重大更改,我们不能立即这样做:https ://github.com/spring-projects/spring-integration/问题/3435

于 2021-08-09T18:15:38.490 回答