Search code examples
javaspringspring-bootelasticsearchpom.xml

An attempt was made to call a method that does not exist ... Correct the classpath


While trying to update an application with spring boot from 2.1.8 to 2.3.4, I managed to resolve some errors and built successfully, but after trying to run the main application the following error message has been killing me

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.hibernate.search.elasticsearch.client.impl.DefaultElasticsearchClientFactory.createClient(DefaultElasticsearchClientFactory.java:92)

The following method did not exist:

    org.elasticsearch.client.RestClientBuilder.setMaxRetryTimeoutMillis(I)Lorg/elasticsearch/client/RestClientBuilder;

The org.elasticsearch.client.RestClientBuilder, is available from the following locations:

    jar:file:/Users/pei/.m2/repository/org/elasticsearch/client/elasticsearch-rest-client/7.6.2/elasticsearch-rest-client-7.6.2.jar!/org/elasticsearch/client/RestClientBuilder.class

The hierarchy was loaded from the following locations:

    org.elasticsearch.client.RestClientBuilder: file:/Users/pei/.m2/repository/org/elasticsearch/client/elasticsearch-rest-client/7.6.2/elasticsearch-rest-client-7.6.2.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.elasticsearch.client.RestClientBuilder


Process finished with exit code 1

I've done a lot research, including this SO question and a lot of similar cases to mine, but I found they are eventually different. For example, in my cases there seems to be only one location offering the method class... and results of ./mvnw dependency:tree -Pwar | grep elasticsearch gives

[INFO] +- org.hibernate:hibernate-search-elasticsearch:jar:5.11.2.Final:compile
[INFO] |  +- org.elasticsearch.client:elasticsearch-rest-client:jar:7.6.2:compile
[INFO] |  +- org.elasticsearch.client:elasticsearch-rest-client-sniffer:jar:5.6.8:compile
[INFO] +- org.elasticsearch.plugin:analysis-icu:jar:5.0.0-alpha5:test
[INFO] +- org.elasticsearch.plugin:analysis-kuromoji:jar:5.0.0-alpha5:test

I assume elasticsearch-rest-client and elasticsearch-rest-client-sniffer are two different dependencies, so it's not like they are conflicting?

Edit:

After I add the following dependency suggested by the comment from @gowridev

<dependency>
    <groupId>org.hibernate.search</groupId>
    <artifactId>hibernate-search-backend-elasticsearch</artifactId>
    <version>6.0.0.Beta3</version>
</dependency>

The error remains but changes slightly

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.<clinit>(HibernateSearchSessionFactoryObserver.java:37)

The following method did not exist:

    org.hibernate.search.engine.Version.touch()V

The methods clas, org.hibernate.search.engine.Version, is available from the following locations:

    jar:file:/Users/pei/.m2/repository/org/hibernate/search/hibernate-search-engine/6.0.0.Beta3/hibernate-search-engine-6.0.0.Beta3.jar!/org/hibernate/search/engine/Version.class
    jar:file:/Users/pei/.m2/repository/org/hibernate/hibernate-search-engine/5.11.2.Final/hibernate-search-engine-5.11.2.Final.jar!/org/hibernate/search/engine/Version.class

The clas hierarchy was loaded from the following locations:

    org.hibernate.search.engine.Version: file:/Users/pei/.m2/repository/org/hibernate/search/hibernate-search-engine/6.0.0.Beta3/hibernate-search-engine-6.0.0.Beta3.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.hibernate.search.engine.Version


Process finished with exit code 1

Solution

  • It turns out that I misunderstood the error message.

    Correct the classpath of your application so that it contains a single, compatible version of org.hibernate.search.engine.Version
    

    When searching for this message, others mostly have problems with dependencies repeated in different places. That makes me think mine is the same reason. That is not.

    The key is not that the version is not single, but is that it is not compatible.

    Simply,

    org.hibernate.search.elasticsearch.client.impl.DefaultElasticsearchClientFactory.createClient()
    

    this method is calling

    org.elasticsearch.client.RestClientBuilder.setMaxRetryTimeoutMillis()
    

    but as the error message pointed out, it does not exist.

    It does not exist not because it was there but the computer failed to find out that. It is simply just not there. elasticsearch 7.6.2 has no such method; it has been removed since elasticsearch 7.

    As a solution, I downgrade my elasticsearch to 6.8.13 and everything works well now. Just add this to pom.xml/<properties>

    <elasticsearch.version>6.8.13</elasticsearch.version>
    

    If there is a better/more proper solution please kindly let me know.