java.lang.NoSuchMethodError: org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder.setSource [英] java.lang.NoSuchMethodError: org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder.setSource

查看:282
本文介绍了java.lang.NoSuchMethodError: org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder.setSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行使用子项目的 spring boot 父项目,该项目又使用具有 elasticsearch 依赖项的项目(ES 项目)和用于传输客户端的 elasticsearch 配置 bean.
子项目使用 Spring Data ES 存储库,这些存储库由项目中的相应注释启用.
这些是子级中使用的配置注释:

I am trying to run the spring boot parent project which uses child project, which in turn uses project(ES project) which has elasticsearch dependencies and elasticsearch config bean for transport client.
The child project uses Spring Data ES repositories, which are enabled by a respective annotation in a project.
These are config annotations used in the child:

@Configuration
@ComponentScan("package")
@EntityScan("package3")
@EnableJpaRepositories("package2")
// enables only es repos for current project, ESProject has this annotation for its packages respectively
@EnableElasticsearchRepositories("package1")

父项目在 ES 项目和子项目的所有包上都有唯一的 @SPringBootApplication.

The parent project has the only @SPringBootApplication on all packages of ES project and child one.

父pom:

<dependencies>
        <dependency>
            <groupId>org.groupid</groupId>
            <artifactId>ChildProject</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
        </dependency>
   <!-- ... -->
</dependencies>

子 pom:

<dependencies>
        <dependency>
            <groupId>org.groupid</groupId>
            <artifactId>ESProject </artifactId>
            <version>1.1-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <!-- exclusions -->
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
        </dependency>
</dependencies>

ESProject Pom:

ESProject Pom:

   <dependencies>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>6.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
            <version>6.4.1</version>                    
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-elasticsearch</artifactId>
            <version>3.1.1.RELEASE</version>            
        </dependency>
   </dependencies> 

父项目是pom的一个模块,使用Spring Boot 2.0.5.RELEASE.

The parent project is a module of pom, which uses Spring Boot 2.0.5.RELEASE.

当我运行父项目时,我得到了这个.显然存在一些依赖冲突,但我无法弄清楚它们.

When I run a parent project I am getting this. Clearly there are some dependencies conflicts but I can't quite figure out them.

nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.NumberKeyedRepository]: Constructor threw exception; 

  nested exception is java.lang.NoSuchMethodError: org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder.setSource(Ljava/lang/String;)Lorg/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder;

另外,值得注意的是,如果我在其他项目中使用 ESProject,我不会收到此异常,但我在这些项目中没有 Spring Data ES Repos.

Also, it's worth noting if I use ESProject in other projects I don't get this exception but I don't have Spring Data ES Repos in those projects.

推荐答案

在您的设置中,Spring Data Elasticsearch 和 Elasticsearch 库版本非常混乱.让我试着想象一下我们得到了什么:

You have a pretty mix-up of Spring Data Elasticsearch and Elasticsearch library versions in your setup. Let me try to visualize what we got:

Spring Boot 2.0.5 
  +- Elasticsearch                  5.6.11
  +- Data Kay.SR10
    +- Spring Data Elasticsearch    3.0.10
      +- Elasticsearch              5.5.0   

Boot 2.0.5 引入 ES 5.6.11,但同时通过 ES 的 Spring Data Kay 版本 5.5.0 和 SDES 的 3.0.10(这不是很好,但应该可以工作).

Boot 2.0.5 pulls in ES 5.6.11 but at the same time via the Spring Data Kay releasetrain version 5.5.0 of ES and 3.0.10 of SDES (which is not nice but should work).

Spring Data Elasticsearch   3.1.1
  +- Elasticsearch          6.2.2

您定义了依赖于 ES 6.2.2 的 SDES 3.1.1

you define SDES 3.1.1 which relies on ES 6.2.2

Elasticsearch               6.4.1

最后你定义 ES 版本为 6.4.1

finally you define the ES version to be 6.4.1

至于您看到的错误:您的应用程序使用的代码需要在 ES 客户端库中提供以下函数(使用类型的完全限定名称):

As for the error you see: The code that your application uses expects the following function to be available in the ES client libraries (using fully qualified names for the types):

org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder.setSource(java.lang.String)

这个方法存在于 ES 5.5 中,但在那里已经被弃用(摘自代码):

This method existed in ES 5.5, but was already deprecated there (excerpt from the code):

    /**
     * The mapping source definition.
     * @deprecated use {@link #setSource(String, XContentType)}
     */
    @Deprecated
    public PutMappingRequestBuilder setSource(String mappingSource) {
        request.source(mappingSource);
        return this;
    }

在 ES6 中,此方法已被删除,仅存在带有附加 XContentType 参数的方法 - SDES 在此版本中使用该方法.

in ES6 this method was removed and only the one with the additional XContentType parameter exists - which is used by SDES for this version.

因此您的应用程序将 SDES 3.0 与无法工作的 ES 6 库结合使用.

So your application loads SDES 3.0 in combination with ES 6 libraries which cannot work.

因此,您应该使用 Boot 2.1 或 2.2 将依赖项更新为一致的版本 在这里检查版本矩阵

So you should update your dependencies to a consistent version either using Boot 2.1 or 2.2 check the version matrix here

这篇关于java.lang.NoSuchMethodError: org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder.setSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆