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

…衆ロ難τιáo~ 提交于 2021-02-11 15:15:23

问题


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")

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

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

Child 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:

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

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;

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.


回答1:


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

you define SDES 3.1.1 which relies on ES 6.2.2

Elasticsearch               6.4.1

finally you define the ES version to be 6.4.1

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)

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;
    }

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

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

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



来源:https://stackoverflow.com/questions/62287683/java-lang-nosuchmethoderror-org-elasticsearch-action-admin-indices-mapping-put

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!