1

我正在尝试将 Jest 0.0.6 ElasticSearch 客户端与 SpringBoot 1.4 一起使用,并出现以下错误。我认为这是因为 SpringBoot 尝试自动创建一个 Jest 客户端以及对其进行健康检查,但是旧的 Jest 客户端没有一些必需的类。

任何想法如何解决这个问题?

我需要连接到旧的 ElasticSearch v0.90.5 服务器,目前我无法升级。如果您对如何最好地从 SpringBoot 连接到这样的旧版本有任何想法,那也将非常有帮助。

Caused by:org.springframework.beans.factory.UnsatisfiedDependencyException:

Error creating bean with name 'metricsEndpointMetricReader' defined in class path resource 

...

[org/springframework/boot/actuate/autoconfigure/ElasticsearchHealthIndicatorConfiguration$ElasticsearchJestHealthIndicatorConfiguration.class]: 
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthIndicator]: 
Factory method 'elasticsearchHealthIndicator' threw exception; nested exception is java.lang.NoClassDefFoundError: io/searchbox/action/Action; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration ': Bean instantiation via constructor failed; nested exception is    
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration$$EnhancerBySpringCGLIB$$909d8b5d]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'elasticsearchHealthIndicator' defined in class path resource [org/springframework/boot/actuate/autoconfigure/ElasticsearchHealthIndicatorConfiguration$ElasticsearchJestHealthIndicatorConfiguration.class]: Bean instantiation via factory method failed; nested exception is 
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthIndicator]: Factory method 'elasticsearchHealthIndicator' threw exception; nested exception is java.lang.NoClassDefFoundError: io/searchbox/action/Action

来自 Spring Boot 1.4 发行说明:

"开玩笑的支持

如果 Jest 在类路径上,Spring Boot 会自动配置一个 JestClient 和一个专用的 HealthIndicator。即使 spring-data-elasticsearch 不在类路径中,这也允许您使用 Elasticsearch。”

4

1 回答 1

1

我在这个开玩笑的github 页面中找到了。如果你使用 es 0.90.5,那么你必须使用jest 0.0.6. 并且,有一个 spring boot 依赖父级,指定 jest 的版本是2.0.3

<jest.version>2.0.3</jest.version>

自动配置代码位于:org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration

此自动配置类将在io.searchbox.client.JestClient添加到您的类路径时加载。

这是按Condition帧实现的:@ConditionalOnClass(JestClient.class)

您可以在此处找到有关 Condition 框架的更多信息

通过添加排除来排除此自动配置以启动类:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication
@EnableAutoConfiguration(exclude = { JestAutoConfiguration.class})
public class App {

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

将此排除添加到您启动类后。您可以配置您拥有的开玩笑客户端。

于 2016-11-09T05:06:47.617 回答