Elasticsearch RestHighLevelClient 缺少传递依赖项
Elasticsearch RestHighLevelClient missing transitive dependencies
我正在尝试通过此依赖项使用 RestHighLevelClient
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.0.1</version>
</dependency>
但我一直在 RestHighLevelClient
class 中收到 ClassNotFoundExceptions。
当我尝试连接这个 bean 时 (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[=12=](<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[=12=](<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[=12=](<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.call(DeploymentManagerImpl.java:192) [148 skipped]
at io.undertow.servlet.core.DeploymentManagerImpl.call(DeploymentManagerImpl.java:174)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction.call(ServletRequestContextThreadSetupAction.java:42)
at io.undertow.servlet.core.ContextClassLoaderSetupAction.call(ContextClassLoaderSetupAction.java:43)
似乎缺少大量的传递依赖项
更新
原来这里发生了两件事。
正如@miroh 在下面指出的那样,我需要明确定义 org.elasticsearch:elasticserach:6.0.1
依赖关系,这样我就不会引入错误的版本。不确定为什么这是必要的,但似乎确实是必要的......(也在这里引用:https://github.com/elastic/elasticsearch/issues/26959)
我的项目是一个多模块 Spring 项目,有许多其他依赖项。显然,某些 Spring/Springboot 依赖项依赖于 spring-data-elasticsearch
,而 spring-data-elasticsearch
又依赖于 org.elasticsearch:elasticsearch:2.4.6
。我通过将 elasticsearch:6.0.1 版本添加到我父 pom.xml
的依赖管理部分来解决这些冲突的 elasticsearch 版本。这告诉 Maven 在存在依赖冲突时使用版本 6.0.1。
尝试添加以下依赖项。
<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>
添加
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>${es.version}</version>
</dependency>
我正在尝试通过此依赖项使用 RestHighLevelClient
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.0.1</version>
</dependency>
但我一直在 RestHighLevelClient
class 中收到 ClassNotFoundExceptions。
当我尝试连接这个 bean 时 (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[=12=](<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[=12=](<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[=12=](<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.call(DeploymentManagerImpl.java:192) [148 skipped]
at io.undertow.servlet.core.DeploymentManagerImpl.call(DeploymentManagerImpl.java:174)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction.call(ServletRequestContextThreadSetupAction.java:42)
at io.undertow.servlet.core.ContextClassLoaderSetupAction.call(ContextClassLoaderSetupAction.java:43)
似乎缺少大量的传递依赖项
更新
原来这里发生了两件事。
正如@miroh 在下面指出的那样,我需要明确定义
org.elasticsearch:elasticserach:6.0.1
依赖关系,这样我就不会引入错误的版本。不确定为什么这是必要的,但似乎确实是必要的......(也在这里引用:https://github.com/elastic/elasticsearch/issues/26959)我的项目是一个多模块 Spring 项目,有许多其他依赖项。显然,某些 Spring/Springboot 依赖项依赖于
spring-data-elasticsearch
,而spring-data-elasticsearch
又依赖于org.elasticsearch:elasticsearch:2.4.6
。我通过将 elasticsearch:6.0.1 版本添加到我父pom.xml
的依赖管理部分来解决这些冲突的 elasticsearch 版本。这告诉 Maven 在存在依赖冲突时使用版本 6.0.1。
尝试添加以下依赖项。
<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>
添加
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>${es.version}</version>
</dependency>