【问题标题】:Springboot 1.4 + Jest 0.0.6Springboot 1.4 + Jest 0.0.6
【发布时间】:2016-09-09 11:20:01
【问题描述】:

我正在尝试将 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。”

【问题讨论】:

  • 请在 pom 或 gradle 构建文件中包含执行器依赖项。我建议使用此链接 start.spring.io 来引导您的应用程序。
  • 执行器在此更改之前都正常工作,缺少的类来自 Jest 库所以不知道如何解决它?

标签: java spring-boot elasticsearch-jest


【解决方案1】:

我在这个jest 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框架here

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

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);
    }
}

将此排除添加到您的启动类后。你可以配置你自己的 jest 客户端。

【讨论】:

  • 感谢您提供的信息,在 ES 开始出现故障后,我设法获得了升级 ES 的批准,所以现在我不再遇到此问题。也许其他人会看到这一点并进行测试。
  • @EnableAutoConfiguration 注释中的排除对我有用。
猜你喜欢
  • 1970-01-01
  • 2016-12-17
  • 2015-04-15
  • 2015-06-15
  • 2022-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多