我试图通过这个依赖项来使用RestHighLevelClient
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.0.1</version>
</dependency>但是我一直在ClassNotFoundExceptions的RestHighLevelClient类。
当我试图连接这个豆子时(AwsAmsElasticsearchClientConfig.java:
@Bean(name = "elasticsearchRestClient")
public RestHighLevelClient getElasticsearchRestClient() {
RestClientBuilder restClientBuilder = RestClient.builder(
new HttpHost(HOST, PORT, SCHEME));
restClientBuilder.setHttpClientConfigCallback(
new RestClientBuilder.HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
httpClientBuilder.addInterceptorLast(buildAwsSigningRequestInterceptor());
// add SSL config if needed
// httpClientBuilder.setSSLContext(null);
return httpClientBuilder;
}
}
);
return new RestHighLevelClient(restClientBuilder);
}我收到以下错误:
19:51:11.026 ERROR [ main] SpringApplication - Application startup failed
java.lang.ClassNotFoundException: org.elasticsearch.common.CheckedConsumer
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) [1 skipped]
at com.glassdoor.applicantManagement.aws.AwsAmsElasticsearchClientConfig.getElasticsearchRestClient(AwsAmsElasticsearchClientConfig.java:63) [2 skipped]
at com.glassdoor.applicantManagement.aws.AwsAmsElasticsearchClientConfig$$EnhancerBySpringCGLIB$$c8f9ed07.CGLIB$getElasticsearchRestClient$0(<generated>)
Wrapped by: java.lang.NoClassDefFoundError: org/elasticsearch/common/CheckedConsumer
at com.glassdoor.applicantManagement.aws.AwsAmsElasticsearchClientConfig.getElasticsearchRestClient(AwsAmsElasticsearchClientConfig.java:63) [2 skipped]
at com.glassdoor.applicantManagement.aws.AwsAmsElasticsearchClientConfig$$EnhancerBySpringCGLIB$$c8f9ed07.CGLIB$getElasticsearchRestClient$0(<generated>)
at com.glassdoor.applicantManagement.aws.AwsAmsElasticsearchClientConfig$$EnhancerBySpringCGLIB$$c8f9ed07$$FastClassBySpringCGLIB$$fba1a4f2.invoke(<generated>)
at com.glassdoor.applicantManagement.aws.AwsAmsElasticsearchClientConfig$$EnhancerBySpringCGLIB$$c8f9ed07.getElasticsearchRestClient(<generated>) [2 skipped]
at java.lang.reflect.Method.invoke(Method.java:498) [3 skipped]
Wrapped by: java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: org/elasticsearch/common/CheckedConsumer
at com.glassdoor.applicantManagement.aws.AwsAmsElasticsearchClientConfig.getElasticsearchRestClient(AwsAmsElasticsearchClientConfig.java:63) [2 skipped]
at com.glassdoor.applicantManagement.aws.AwsAmsElasticsearchClientConfig$$EnhancerBySpringCGLIB$$c8f9ed07.CGLIB$getElasticsearchRestClient$0(<generated>)
at com.glassdoor.applicantManagement.aws.AwsAmsElasticsearchClientConfig$$EnhancerBySpringCGLIB$$c8f9ed07$$FastClassBySpringCGLIB$$fba1a4f2.invoke(<generated>)
at com.glassdoor.applicantManagement.aws.AwsAmsElasticsearchClientConfig$$EnhancerBySpringCGLIB$$c8f9ed07.getElasticsearchRestClient(<generated>) [2 skipped]
at java.lang.reflect.Method.invoke(Method.java:498) [3 skipped]
Wrapped by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'getElasticsearchRestClient' threw exception; nested exception is java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: org/elasticsearch/common/CheckedConsumer
at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:192) [148 skipped]
at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:174)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)它看起来像是丢失了大量的传递依赖项。

更新
结果这里发生了两件事。
org.elasticsearch:elasticserach:6.0.1依赖关系,这样才不会出现错误的版本。不知道为什么这是必要的,但它似乎确实是必要的.(此处还引用:https://github.com/elastic/elasticsearch/issues/26959)spring-data-elasticsearch,后者依赖于org.elasticsearch:elasticsearch:2.4.6。我通过将elasticsearch:6.0.1版本添加到父pom.xml的依赖关系管理部分来解决elasticsearch的这些冲突版本。这告诉maven在存在依赖冲突时使用6.0.1版本。发布于 2018-02-24 07:37:29
尝试添加以下依赖项。
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>6.0.1</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>6.0.1</version>
</dependency>发布于 2022-04-01 10:53:18
添加
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>${es.version}</version>
</dependency>https://stackoverflow.com/questions/48959212
复制相似问题