如何解决试图调用一个不存在的方法...纠正类路径
当尝试使用从2.1.8
到2.3.4
的Spring Boot更新应用程序时,我设法解决了一些错误并成功构建,但是尝试运行主应用程序后,以下错误消息已被终止我
***************************
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
我做了很多研究,包括this SO question和很多与我相似的案例,但是我发现它们最终是不同的。例如,在我的情况下,似乎只有一个位置提供method class
...,而./mvnw dependency:tree -Pwar | grep elasticsearch
的结果给出
[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
我假设elasticsearch-rest-client
和elasticsearch-rest-client-sniffer
是两个不同的依赖项,所以就好像它们没有冲突吗?
编辑:
我添加了@gowridev注释中建议的以下依赖项
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-backend-elasticsearch</artifactId>
<version>6.0.0.Beta3</version>
</dependency>
错误仍然存在,但会稍微改变
***************************
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
解决方法
事实证明我误解了错误消息。
Correct the classpath of your application so that it contains a single,compatible version of org.hibernate.search.engine.Version
搜索此消息时,其他人大多遇到在不同地方重复依赖的问题。那使我认为我的是同样的原因。不是。
关键不是该版本不是 单个 ,而是它不是 兼容 。
简单
org.hibernate.search.elasticsearch.client.impl.DefaultElasticsearchClientFactory.createClient()
此方法正在调用
org.elasticsearch.client.RestClientBuilder.setMaxRetryTimeoutMillis()
但是如错误消息所指出,它不存在。
不存在它不是因为它在那里,但是计算机无法找到它。它只是不在那里。 elasticsearch 7.6.2
没有这种方法;自elasticsearch 7
起已将其删除。
作为解决方案,我将elasticsearch
降级为6.8.13
,现在一切正常。只需将其添加到pom.xml/<properties>
<elasticsearch.version>6.8.13</elasticsearch.version>
如果有更好/更合适的解决方案,请告诉我。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。