首页 > 解决方案 > java.lang.NoSuchMethodError: io.searchbox.action.Action.getURI()Ljava/lang/String

问题描述

在构建我的 Spring Boot 应用程序时出现错误。我正在使用 ES,当 jestClient 调用执行方法时出现错误。错误:

原因:org.springframework.beans.factory.BeanCreationException:创建名为“configService”的bean时出错:调用init方法失败;嵌套异常是 java.lang.NoSuchMethodError: io.searchbox.action.Action.getURI()Ljava/lang/String;

错误来自 jestHttpClient.class 的执行方法

public <T extends JestResult> T execute(Action<T> clientRequest, RequestConfig requestConfig) throws IOException {
    HttpUriRequest request = this.prepareRequest(clientRequest, requestConfig);
    CloseableHttpResponse response = null;

    JestResult var5;
    try {
        response = this.executeRequest(request);
        var5 = this.deserializeResponse(response, request, clientRequest);
    } catch (HttpHostConnectException var14) {
        throw new CouldNotConnectException(var14.getHost().toURI(), var14);
    } finally {
        if (response != null) {
            try {
                response.close();
            } catch (IOException var13) {
                log.error("Exception occurred while closing response stream.", var13);
            }
        }

    }

    return var5;

}

标签: javaspring-bootelasticsearchkuberneteselasticsearch-jest

解决方案


这是一个常见错误,当您编译代码中引用的类的不同版本时会发生这种错误。这可能是因为您将依赖项导入了两次。

例如,您可以手动导入一个依赖项,该依赖项包含io.searchbox.action.Actionio.searchbox.action.Action也导入另一个版本的另一个依赖项中的依赖项。

只需注意您正在编译的版本,因为在 Jest 最新版本中 getURL 如下

String getURI(ElasticsearchVersion elasticsearchVersion);

但在 5.3.4 上如下

String getURI();

推荐阅读